问题
Is there a way we can test that we ended up at the expected path with rspec?
Something like:
it "should be the forgot password path" do
response.should redirect_to(new_user_password_path)
end
This gives me an error:
Failure/Error: response.should redirect_to(new_user_password_path)
ArgumentError:
@request must be an ActionDispatch::Request
回答1:
I had this problem once, and it was because the capybara visit method doesn't set the @requests variable, the one that rails use to do the redirection assertion (the should redirect_to calls the rails assert_redirected_to).
It's sad, but you have to test it differently, like checking the page's content, for instance.
来源:https://stackoverflow.com/questions/9797509/rspec-make-sure-we-ended-up-at-correct-path