DevelopWithPassion.Specifications

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:

  1. sut (system under test) is created automatically, it can also be overrode by sut_factory.create_using() syntax.
  2. Exception assertion is simple, spec.catch_exception in because block, then do check in it block: spec.exception_thrown.ShouldBeAn<ArgumentException>()
  3. All kinds of adapters to different mock libraries.
  4. 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,

  1. By using the default folder created by NuGet, the old centralized lib folder is not split into each package’s own lib folder.
  2. MSBuild is called by rake, instead of nant, it saved a lot of time by not doing nant include/exclude file organizing work.
  3. Ruby/Rake build is clean and powerful!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s