I ran into this problem today using RSpec with Webrat. I had this piece of code:
it 'should redirect to somewhere' do
visit page_that_redirects_somewhere_path
response.should redirect_to(somewhere_else_path)
end
I know that the controller is redirecting, but for some reason, in the test, the response was not showing a redirect.
I looked at response.body and saw that it was the html for the page it was supposed to be redirected to.
The problem is that Webrat's visit()
does more work for you and follows the redirect.
So the response in the test is the response AFTER the redirect as happened and the new page is rendered.
The solution:
it 'should redirect to somewhere' do
# change visit() to get().
get page_that_redirects_somewhere_path
response.should redirect_to(somewhere_else_path)
end
I'm using Rails 2.3.8, Webrat 0.7.0, RSpec 1.3.1 and RSpec-rails 1.3.1