确保我们以正确的路径结束

确保我们以正确的路径结束

本文介绍了Rspec 确保我们以正确的路径结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以测试我们是否在使用 rspec 的预期路径上结束了?

Is there a way we can test that we ended up at the expected path with rspec?

类似于:

it "should be the forgot password path" do
  response.should redirect_to(new_user_password_path)
end

这给了我一个错误:

 Failure/Error: response.should redirect_to(new_user_password_path)
 ArgumentError:
   @request must be an ActionDispatch::Request

推荐答案

我曾经遇到过这个问题,那是因为 capybara 的访问方法没有设置 @requests 变量,这个变量是 rails 用来做重定向断言的(应该redirect_to 调用rails assert_redirected_to).

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.

这篇关于Rspec 确保我们以正确的路径结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:39