NBehave + NSpec
So, quickly, I decided to go ahead and throw NSpec into the mix on top of NBehave. Why not! 🙂
Here is what the example from my previous post would look like using NSpec:
[Test, Story] public void Load_checkout_information() { CheckoutOrderDTO checkoutOrderDTO = new CheckoutOrderDTO(); ShoppingCartDTO shoppingCartDTO = new ShoppingCartDTO(); IList<LookupDTO> listOfCreditCards = new List<LookupDTO>(); Story story = new Story("Load checkout information"); story .AsA("controller that is responsible for performing the checkout process") .IWant("to load the checkout information based on the current user's pending order") .SoThat("I can edit the customer's information before submitting the order"); story .WithScenario("Order is ready to be checked out") .Given("controller is prepared", delegate { PrepareController(controller, "checkout", "index"); }) .And("pending order is retrieved from checkout service", delegate { Expect.Call(mockCheckoutService.GetOrderForCheckout()).Return(checkoutOrderDTO); }) .And("shopping cart is retrieved from shopping cart service", delegate { Expect.Call(mockBasketService.GetShoppingCart()).Return(shoppingCartDTO); }) .And("list of acceptable credit card types are retrieved from credit card lookup service", delegate { Expect.Call(mockCreditCardLookupService.GetAllCreditCardTypes()).Return(listOfCreditCards); }) .And("mock object framework has stopped recording", delegate { mockery.ReplayAll(); }) .When("the index action is executed", delegate { controller.Index(); }) .Then("the pending order should exist in the property bag with key of", PB.CheckoutOrder, delegate(string key) { Specify.That(controller.PropertyBag[key]).ShouldEqual(checkoutOrderDTO); }) .And("the shopping cart should exist in the property bag with key of", PB.ShoppingCart, delegate(string key) { Specify.That(controller.PropertyBag[key]).ShouldEqual(shoppingCartDTO); }) .And("the list of accepted credit card types should exist in the property bag with key of", PB.AllCreditCardTypes, delegate(string key) { Specify.That(controller.PropertyBag[key]).ShouldEqual(listOfCreditCards); }); }
Of course I know that the use of NSpec here is basically just syntactic sugar over the Assert statement, but it definitely reads better.