【问题标题】:Rspec make sure we ended up at correct pathRspec 确保我们以正确的路径结束
【发布时间】:2012-03-21 01:36:57
【问题描述】:

有没有一种方法可以通过 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

【问题讨论】:

    标签: ruby-on-rails rspec routes


    【解决方案1】:

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

    很遗憾,但您必须以不同的方式对其进行测试,例如检查页面的内容。

    【讨论】:

    • 无赖。你的意思是“很伤心”吗?
    猜你喜欢
    • 2019-07-11
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    相关资源
    最近更新 更多