I got a short break for some BDD play time this afternoon, so I finally fork JP’s repository, did a git clone, then try to follow his instruction for how to build.
A minor issue encountered, ICreateDelegatesThatThrowExceptions is missing, seems only one method needed there, so I created it manually, build passed.
Quickly convert one of my old test to new BDD style, worked like a charm as it promised.
public class OrderTranslatorSpecs
{
[Subject(typeof(OrderTranslator))]
public class When_translate_NHibernate_model_to_csla_bo : Observes<OrderTranslator>
{
static Order result;
Because b = () =>
{
var orderModel = new OrderModel
{
CustomerName = "A customer"
};
orderModel.AddLineItem(new LineItemModel { Name = "Linteitme1" });
result = sut.From(orderModel);
};
It should_return_valid_csla_bo = () =>
{
result.IsValid.ShouldBeTrue();
result.CustomerName.ShouldEqual("A customer");
result.LineItems.Count.ShouldEqual(1);
result.IsDirty.ShouldBeFalse();
result.IsNew.ShouldBeFalse();
};
}
}
Some nice feature comparing to the classci MachineSpecification framework:
- sut (system under test) is created automatically, it can also be overrode by sut_factory.create_using() syntax.
- Exception assertion is simple, spec.catch_exception in because block, then do check in it block: spec.exception_thrown.ShouldBeAn<ArgumentException>()
- All kinds of adapters to different mock libraries.
- mocking is done by fake setup in establish block. mock/fake can happen on a non-interfaced property, including static class, fake auto-rest after test. see example here.
Other cool stuff from JP’s project structure,
- By using the default folder created by NuGet, the old centralized lib folder is not split into each package’s own lib folder.
- MSBuild is called by rake, instead of nant, it saved a lot of time by not doing nant include/exclude file organizing work.
- Ruby/Rake build is clean and powerful!