Came across this interesting test failure after upgrading a project to Rails 2.2.2 earlier today:
should route users's 'destroy' action correctly The recognized options <{"action"=>"show", "id"=>"1", "controller"=>"users"}> did not match <{"action"=>"destroy", "id"=>"1", "controller"=>"users"}>, difference: <{"action"=>"destroy"}>
Turns out that rspec’s route_for
method behaves differently when run against Rails 2.2+ due to the routing changes. The controller in question is setup as a resource, so the “destroy” action must be called via an HTTP DELETE, not a GET.
The failing line in the test looked like this:
route_for(:controller => 'users', :action => 'destroy', :id => 1).should == '/users/1'
The fix was simple enough:
route_for(:controller => 'users', :action => 'destroy', :id => 1).should == {:path => '/users/1', :method => :delete}
Hope this helps anyone who is experiencing the same problem.
Thanks for the post, man. I had the same problem, and your post came up right on top of a Google search for “rspec route_for”. Nice.