Thursday, 3PM – Railslove has fun

In Bath…
Red has fun!

In Hamburg…

Sven and Thorsten have fun

Waldorf  and Stadler have fun

In Cologne…

Tatjana has fun

Jan, Lars, Bumi have fun

Jan and Porn George have fun

Jakob, Welf, Stefan have fun

Rspec Is Lovely

Several months ago my choice of testing framework was TestUnit + Shoulda. Rspec looked good, but I didn’t see what made it particularly special.

When working on a client project which was using Rspec I decided to properly look into it. What I found was that it made my tests incredibly organised and very easy to follow. Below are some methods I take when writing Rspec tests.

Describes

Don’t skimp on them! If you find your “it”s becoming too long or describing too much then it is usually a good sign that you should be using a describe.

Setting The Subject

I find setting the subject great for focussing your testing. Setting the subject tells Rspec…what the subject of the is test is. i.e. what these tests are in reference to.

Its

This is probably easier to just show in code rather than describe…

Context

This is great for outlining different outcomes for a method:

Let

From the docs: “Generates a method whose return value is memoized after the first call.”

Specify

Specify is just like it. I like to use it when I am not testing against a subject:

One Last Thing

You can specify Rspec configurations in a .rspec file. I have the color and profile options which: make pretty colours and will display the 10 slowest tests.

That’s not all! You should definitely look at the Rspec source code.

Happy Rspec’in!

Edit:

Thanks to @bumi and @clemensk for reminding me about expect.

Using expect is a lot nicer than using the good old lambda route:

Say Hey to Nybbl.me

nybbl

This week we launched a new project called Nybbl.me.

“Nybbl.me gives you an easy way to share and consume knowledge.”

We hope you enjoy it! You can follow any developments over on Twitter or on the Nybbl.me blog.