I have moved!

My new blog is at lindsaar.net

All the old content will stay here though. But check out the new blog

¿ 20/7/2007 - Behaviour Driven Design, RSpec and Textmate's TODO List

While I was doing specifications, I found that I lost track of where my unimplemented specifications were.  To handle that, I made a little modification to Textmate's TODO Bundle.  You can scroll down about a page to how I did it, or you can see the why :)

If you are like me and use RSpec, you probably find yourself doing behaviour driven design...
 yes, I said design, not development.

What am I talking about?

Well, I was reading this article called Mock Objects not Roles by Steve Freeman, Tim Mackinnon, Nat Pryce and Joe Walnes, which is a great introduction to the use of Mocks in testing and how and why you should use them.

While I was reading it, I ran across the section entitled Need-Driven Development which discusses how, by using Mocks, you can quickly work out the requirements of the other objects in your system.  In a sense, defining the behaviour and requirements of the object your defining the specifications for, creates a situation where you are actively designing the specifications of the objects that interact with it.

This didn't really strike me as something new, more of something that I was already doing but didn't realise it!

As I am doing my specifications, I might write a mock for another class.  That mock has an interface of whatever it is.

Immediately on writing that mock, I flip over to that class's spec file, and write in an unimplemented specification.

Then I end up with a whole bunch of specifications needing to be done, scattered through all my files!

After a few hours of programming, it is not unusual to have a bunch of unimplemented specs through your files.  Where to find them?

Autotest is not very useful here as it just gives you a bunch of yellow asterisks, you can run an rcov or use RSpec's own documenting feature, but I wanted something right there that I could use within textmate that would link back to the unimplemented spec in a no fuss "Here it is, fix it".

Plus, I was used to using TODO before I had such wonderful things like RSpecs to define my TODOs!

So I went and had a look at the TODO list, and voila... there is the answer!

Sure enough, a few minutes later, I had a list of all my unimplemented specifications starring me in the eye!

How to do this?

Easy.

First, to make this work, you have to write your unimplemented specs as follows:

Unimplemented specs

Spaces before or after the it are not important.  What is important is that you put what it should do inside quotes and not anything on the end of the line (no do, no # comment, nada. just leave a space or two if you must).

As this is what you need to do to get the spec to show as unimplemented during rake spec or autotest, writing your unimplemented specs like this, should be easy.

Then, go to your textmate menu => Bundles => TODO => Preferences

Then on the left panel, at the bottom, click the + sign to add a new marker.

Double click "MY MARKER" and type in UNIMPLEMENTED on the left.

Then type in UNIMPLEMENTED in the Marker: field.

Then put the following REGEX expression into the Pattern field:

/\s+it\s"(\S.*?)"\s+$/i


Then set your color to a nice yellow to match the RSpec colour output and your little box should look something like this:

Image showing how to set your Textmate TODO list to support RSpec Unimplemented Spec finding
Then click DONE and you are DONE!

Now, with just a Ctl-Shift-T you get a TODO list output that includes "Unimplemented" as a section with the file and lines nicely sorted and hyperlinked up for you to jump to them in an instant and looks something like this:

RSpec Textmate TODO List with unimplemented specs

Hope you find it useful.

blogLater

Mikel
Post A Comment! :: Send to a Friend!

¿ 4/10/2007 - Untitled Comment

Posted by Hannes
Thanks Mike! I had some unimplemented specs I'd forgotton where they where. But now I know.
Permanent Link

¿ 4/10/2007 - @ Hannes

Posted by mikel
No problem Hannes :)
Permanent Link

About Me

AKA Raasdnil, this site is about web coding, hosting and all other matters that relate to this... especially Ruby on Rails!

Links