Over a million developers have joined DZone.

The Joy of MSpec

·

I’ve just kicked off a new MVC Framework application today. I’ve been considering moving to more behaviour based testing for a while now and I’ve been intrigued by Aaron Jensen’s descriptions of his MSpec (Machine Specifications) framework. So this afternoon I downloaded the build from here and got coding (just click ‘login as guest’ at the bottom).

It’s very nice. Here’s some tests for my container setup:

 

using System.Web.Mvc;
using Castle.Windsor;
using Machine.Specifications;
using Spark.Web.Mvc;
using Mike.Portslade.Web.IoC;

namespace Mike.Portslade.Web.Tests.IoC.ContainerManagerSpecs
{
public class when_container_is_created
{
Because of = () =>
container = ContainerManager.CreateContainer();

It should_register_HomeController = () =>
container.Kernel.HasComponent("homecontroller");

It should_register_SparkViewFactory = () =>
container.Kernel.HasComponent(typeof (SparkViewFactory));

It should_register_an_IControllerFactory = () =>
container.Kernel.HasComponent(typeof (IControllerFactory));

private static IWindsorContainer container;
}
}

I love the readability of the test code. Sure you have to learn to love the ‘=()=>’, but come on people, lambda syntax is hardly new any more.

When I run this using TestDriven.NET, my test runner of choice for many years now, I get this output:

when container is created
» should register HomeController
» should register SparkViewFactory
» should register an IControllerFactory

The only thing I don’t like is that the ‘It’ has gone missing which is a shame, otherwise this is just what I want from behaviour based testing framework; very low friction and easy to read output.

Well done Aaron, I’m very impressed.

 

Topics:

Published at DZone with permission of Mike Hadlow, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}