Upgrading to Rspec 1.0

I just upgraded one of my Rails projects to Rspec 1.0.2, ran all my old specs to see what would happen, and … crunch. It turns out there are a few gotchas if you were using an older version (instead of starting from scratch–I think they’ll be picking up some new users with this release).

First thing to change in your specs:
context "a model or controller or whatever" do
specify "behavior" do

is now

describe "a model or controller or whatever" do
it "has behavior" do

The description for model blocks should look like:
describe Apple, "with fixtures loaded" do

The string after the model name is optional.

For controller blocks it’s:
describe ApplesController do

You can also use a string in place of the controller name, in which case you’ll need to declare the controller name explicitly.
describe "Submitting new apple description"
controller_name :apples

The setup block is now before(:each).
before(:each) do
[setup actions of some sort]

The syntax for ‘should’ functions has changed.
I had several examples of:

This is now:
User.should respond_to(:authenticate)
Note the lack of an underscore after ‘should’.

The exception to that is the should_not function.
This is correct:
@feed.posts.should_not be(nil)

With these changes, all of my specs are passing again. Did I miss anything that broke for you? Leave a comment.

Links to further documentation:
Writing specs for Rails
General Rspec instructions

2 responses to “Upgrading to Rspec 1.0

  1. It sounds like you missed out on the automatic translator that ships with 1.0 and that is described on the web page.


    I realise it says 0.8 to 0.9, but it works for 0.8 to 1.0 too, as there areen’t any major changes between 0.9 and 1.0.

  2. Thanks for the pointer. That’ll help if I need to convert anything else. I’m impressed by how much Rspec has changed in just the last couple of months. I think the older release I was working from dates back only as far as the start of April.