【发布时间】: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