Hadi Hariri

Sponsors

The Lounge

Wicked Cool Jobs

Syndication

MSpec Live Templates

 

If you’re using MSpec (Machine.Specifications), you’ve no doubt run into the verbosity of it. Here’s a typical specification in MSpec

  1. [Subject("Registering as new a usergroup")]
  2. public class when_requesting_registration_page
  3. {
  4.     Establish context = () =>
  5.     {
  6.     };
  7.  
  8.     Because of = () =>
  9.     {
  10.     };
  11.  
  12.     It should_display_blank_registration_form = () =>
  13.     {
  14.     };
  15. }

 

The code is usually divided into three areas, the Establish that defines the context, Because which is defined as the action to take, and finally one or more benefits that are defined as It sections. Having this layout makes it easier to understand specifications and both the console runner as well as ReSharper’s MSpec runner remove underscores and provide a nice formatting.

Live Templates

However when it comes to typing all this in, well all those brackets and symbols become tiring. For that I normally use ReSharper Live Templates. If you’re not familiar with these, think of them as code snippets that allow interaction. Each template is uniquely identified by a shortcut, which is a series of characters. To invoke it, you simply type the characters and hit TAB. It then inserts some code. Up to this point it’s like a normal snippet. The twist however is that you can then TAB through placeholders and define values (I’ll cover  Live Templates and all the possibilities it allows in a future post).

image

What I’ve been using for a while are some Live Templates for MSpec that allow me to define specifications with a little less effort. The first one is for empty specifications, which is useful for defining scenarios for features and then later proceeding to implement them, named espec. The second one is for the specifications and implementation, named spec.

image

To install them, the easiest way is to just open up Live Templates (ReSharper menu) and Import the following file.

.

image

Obviously these are just two simple versions and can be expanded on. For instance, if you use Behaviors in MSpec, you could write an additional one for that. Feel free to use them for your own needs.


Posted 03-01-2010 4:07 PM by Hadi Hariri
Filed under: ,

[Advertisement]

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco <-- NEW Friend!
NServiceBus <-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)