[rspec-users] params are making my "should redirect_to" test fail - why??

David Chelimsky dchelimsky at gmail.com
Wed Feb 13 13:39:13 EST 2008

On Feb 13, 2008 12:26 PM, Max Williams <toastkid.williams at gmail.com> wrote:
> I'm testing a controller action that redirects to a different action/view,
> sending through some params.  In my test, i'm only specifying the controller
> and action that it should redirect to, but the additional params are making
> it fail!  Here's my test:
>   it "should redirect to batch_saved after completing batch_save" do
>     post 'batch_save', @params
>     response.should redirect_to(:controller => 'admin/users', :action =>
> 'batch_saved')
>   end
> and here's the failure report:
> 'Admin::UserController When logged in as an admin level user should redirect
> to batch_saved after batch_save' FAILED
> expected redirect to {:controller=>"admin/users", :action=>"batch_saved"},
> got redirect to
> "http://test.host/admin/users/batch_saved?music_service_id=1&new_users%5B%5D%5Bemail%5D=mark%40zadeup.com&new_users%5B%5D%5Bfirstname%5D=Mark&new_users%5B%5D%5Bmusic_service_id%5D=1&new_users%5B%5D%5Bschool%5D=&new_users%5B%5D%5Bsurname%5D=Madeup"
> Now, i would expect that since i'm just specifying a controller and action,
> and we redirect to them, that the test would pass.  But the params are
> breaking it (I know this because i changed the controller action to not send
> params through at all and the test passed).  How do i do the test so that it
> doesn't care about the params?

When you use a hash it checks the whole hash, so this is the expected behaviour.

You can either used a named route (if you've got one available) or a
String literal:

response.should redirect_to(admin_users_batch_saved)
response.should redirect_to('/admin/users/batch_saved')

Based on Jay Field's latest advice
(http://blog.jayfields.com/2008/02/testing-expect-literals.html) you
may want to consider the literal.


> --
> View this message in context: http://www.nabble.com/params-are-making-my-%22should-redirect_to%22-test-fail---why---tp15460582p15460582.html
> Sent from the rspec-users mailing list archive at Nabble.com.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list