【问题标题】:Passing GET params to controller with Capybara使用 Capybara 将 GET 参数传递给控制器
【发布时间】:2013-12-17 12:01:31
【问题描述】:

使用 Capybara 测试令牌身份验证的正确方法是什么?这是我所拥有的:

describe ApplicationController do
  let!(:user) { create :user, authentication_token: 1 }

  specify "token should work now" do
    visit "/?auth_token=#{user.authentication_token}"
    # get :index
    response.should_not redirect_to(new_user_session_url)
  end

  specify "token shouldn't work in the future" do
    Timecop.travel(2.weeks)
    visit "/?auth_token=#{user.authentication_token}"
    # get :index
    response.should redirect_to(new_user_session_url)
    Timecop.return
  end
end

如果我没有 get :index 行,测试将失败。但是如果我注释掉那一行,测试就会被保存,但这不应该是正确的方法,因为我上面有visit

我做错了什么?

【问题讨论】:

  • 响应来自get,如果我没记错的话,访问会返回一个页面。我敢打赌,当您有 get :index 注释掉其困惑的响应时。

标签: ruby-on-rails testing rspec devise capybara


【解决方案1】:

事实证明visit 没有将变量传递给控制器​​。将其更改为 get :index, auth_token: user.authentication_token 解决了这个问题。

【讨论】:

    猜你喜欢
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多