Rspec make sure we ended up at correct path

南笙酒味 提交于 2019-12-13 00:54:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!