rornoob.com >

rspec route_for tests failing


11-Aug-2009

Don't you hate it when your tests work on one server but not on another?

That's what happened to me today... rake spec on my development machine gives me a nice 0 failures, but run the same tests on the test server I get a frustrating 16 failures

So what's gone wrong? On the test server I'm getting error messags like these:

Name: UsersController route generation should map { :controller => 'users', :action => 'destroy', :id => 1} to /users/1

Type: Error

Message: Test::Unit::AssertionFailedError in 'UsersController route generation should map { :controller => 'users', :action => 'destroy', :id => 1} to /users/1'

The recognized options <{"action"=>"show", "id"=>"1", "controller"=>"users"}> did not match <{"action"=>"destroy", "id"=>"1", "controller"=>"users"}>, difference: <{"action"=>"destroy"}>

Why does that happen? The code is exactly the same. The configuration files are exactly the same. This problem is frustrating in the least!

After some digging around I found out that the problem was due to newer version of rspec on test server - version 1.2.8 compared with 1.1.12 on the development machine.

It would seem that the newer rspec is stricter (better) than the earlier version. The route_for mthod now requires the HTTP method to be specified if it isn't a GET.

So the solution? Fix up the test specifications to the stricter requirements.

e.g. change

  route_for(:controller => "users", :action => "destroy", :id => "1").should == "/users/1"

to

  route_for(:controller => "users", :action => "destroy", :id => "1").should == {:path => "/users/1", :method => :delete}

Run the tests again...

0 failures

That's better!

| |

del.icio.usDiggblogmarksNewsvineStumbleUponTechnoratiFurlReddit

Comments

RoRnoob said on 10-Aug-2009:
I guess this is a common problem when upgrading to newer versions of rspec.

Looking back at what I just wrote, this looks like the tell-tale signature of needing to refactor your tests:

The recognized options ... did not match ...
Add your comment
Name
Website
Heading
Comment