这是我正在处理的测试用例:
it "should allow you to login" do
visit "/"
fill_in 'Email', :with => 'user@example.org'
fill_in 'Pass', :with => 'password'
click_button 'Login'
current_url.should =~ /dashboard/
end
这个特定的测试失败了。我想知道的是它是否因为无法登录而失败,但因为我检查 current_url 太快而失败。 “等待”直到 click_button 任务执行和 rails 重定向用户的正确方法是什么?
最佳答案
您是否尝试过手动转到主页,使用这些凭据登录,然后查看会发生什么?如果您能够做到,那么您就可以排除它不起作用的想法。
我建议使用内置断言而不是匹配 URL 的名称。像这样:
assert_response(:redirect)
assert_redirected_to(dashboard_path)
在任何一种情况下,您都不必等待按钮被点击。
关于ruby-on-rails - 使用 Rspec 和 Capybara 测试登录重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10707624/