Good news, everyone! There’s a new release of SpecsFor out today. Version 1.1 is a minor update that ships with some additional Resharper Live Templates as well as some Visual Studio snippets for those that are not drinking the Resharper Koolaide (thanks to Brady Gaster) . Additionally, SpecsFor is moving! I’m now on the Github bandwagon (and loving it!), so all code, documentation, and releases will now reside there.
New Templates
One of the big time-savers of using SpecsFor is the set of Resharper Live Templates (and now, Visual Studio snippets!) that help you create your test scenarios quickly and painlessly. SpecsFor actually supports may different patterns for specifying context, and I tell people that they should use which ever approach feels most natural to them. For some, that’s the attribute-based approach for specifying context:
[Given(typeof(TheCarIsNotRunning), typeof(TheCarIsParked))] [Given(typeof(TheCarIsNotRunning))] public class when_the_key_is_turned : SpecsFor<Car> { public when_the_key_is_turned(Type[] context) : base(context){} protected override void When() { SUT.TurnKey(); } [Test] public void then_it_starts_the_engine() { GetMockFor<IEngine>() .Verify(e => e.Start()); } }
Some prefer to put the context directly in the specs:
public class when_the_key_is_turned_alternate_style : SpecsFor<Car> { protected override void Given() { Given<TheCarIsNotRunning>(); Given<TheCarIsParked>(); base.Given(); } protected override void When() { SUT.TurnKey(); } [Test] public void then_it_starts_the_engine() { GetMockFor<IEngine>() .Verify(e => e.Start()); } }
And others (myself included) like the approach of putting context in a base class:
public class when_the_key_is_turned : given.the_car_is_not_running_and_parked { protected override void When() { } } public static class given { public abstract class the_car_is_not_running_and_parked : SpecsFor<Car> { protected override void Given() { } } }
The last release of SpecsFor only shipped with Live Templates for the attribute-based approach. Going forward, I want to have templates for each approach, enabling users to import whichever set of templates they prefer. This release is a step in that direction. Just import either Attribute-* or Inheritance-* templates, and off you go!
What To Do Next?
I have many ideas for where to take SpecsFor next, but I’m not sure what’s actually important to users. If there’s something you’d like to see in the next version, or some scenario that SpecsFor doesn’t handle elegantly, please let me know: submit an issue on Github.