Testing for exceptions in MSpec

Posted by Jens Pettersson on September 10th, 2010

As I’ve said before, we’re using MSpec in our current project and today I needed to make sure a method threw the right kind of exception. This may be really easy, but as I’ve never done this in MSpec before, I had to ask the mighty Google for the answer. When ever I have to do that, I want to write it down somewhere (but I seldom do), and that’s why I’m posting this here.

Consider we have the following, very useful, method in a Very Fragile class:

imageNow we want to make sure that when the bomb is dropped our calling code gets a Potential Dangerous Exception. The following specification will test that this really happens:

That’s it! Using the Catch-class in MSpec will return an Exception and then all you have to do is check that it is of the correct type.

Happy MSpec-ing!

//J

PS. If you wonder why I’m not using our syntax highlighting plugin the simple answer is that I love the Visual Studio theme I’m using and think Daniel should switch to it now! ;)

More MSpec – ReSharper love

Posted by Jens Pettersson on August 27th, 2010

This is a follow up to the post about how ReSharper and Visual Studio messes with your MSpec specifications.

Resharper has built in support for naming inspections which is great for consistency if everyone in the team follows the same rules, but sometimes you just don’t want it. The most common scenario is when writing BDD specs (with tools like Machine.Specifications or MSpec for short).

image

This is a pretty common specification in our current project, and the class name might seem strange if you haven’t done BDD before. But the beauty of this is that the testing framework generates reports with this convention which is extremely readable for non-techincal people.

It will read something like this:

When an already handled customer is processed
the customer should not be processed further

Or whatever you want to check. Our rake task always generates a html-page with all our specifications in a nice and readable format (more on that in a later post).

Well, back on topic! How do we tell Resharper not to scream WARNING, WARNING! at us all the time. We ARE naming things like this on purpose!

As everything always has been done by someone before, I’m only going to give you a link to the solution: http://www.aspiringcraftsman.com/2010/02/resharper-naming-style-for-machine-specifications/

You can add as many naming styles as you like to suit your specifications.

Happy mspeccing!

//J

PS. If you like the Visual Studio theme I’m using, go grab it from my repository over at github. Be sure to read the readme for the right fonts, otherwise the theme will hurt your eyes and probably your babies or kittens too.

Does ReSharper drive you crazy when using MSpec?

Posted by Jens Pettersson on August 19th, 2010

Ask yourself the question in the topic and if the answer is “Yes damn you, YES!!” then this link tip is for you!

http://codebetter.com/blogs/aaron.jensen/archive/2008/10/19/getting-resharper-and-vs-to-play-nice-with-mspec.aspx

Thank you Aaron Jensen! I was going mad with all the ugly indentations and other noise everywhere.

//J


Copyright © 2010 NullReference. Web hosting.