Ale*_*lov 5 ruby-on-rails cucumber capybara
使用OmniAuth(使用omniauth_crowd),如果用户没有提交正确的用户名和密码,我希望将用户重定向回登录页面.它在生产中工作正常,但我测试它有烦人的问题.
要模拟OmniAuth提供程序,我使用以下代码,如OmniAuth插件的作者所推荐:
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:someProvider] = :invalid_credentials
visit_page @page
Run Code Online (Sandbox Code Playgroud)
上面的代码自动(即没有输入用户名和密码)将Capybara重定向到session#failure.我session#failure重定向到了login_path.
因此我最终陷入了一个循环:
redirected more than 5 times, check for infinite redirects. (Capybara::InfiniteRedirectError)
Run Code Online (Sandbox Code Playgroud)
我的案例最好的解决方法是什么?
我在 Omniauth 上也遇到了类似的问题。
不确定是否有解决方法,因为这就是OmniAuth.config.mock_auth有效的方法。
我的解决方案是使用fakewebOmniAuth 模拟来代替。
您可能应该首先查看omniauth_crowd 本身是如何测试的。
这是一个很好的例子:
https://github.com/robdimarco/omniauth_crowd/blob/master/spec/omniauth/strategies/crowd_spec.rb#L49-69
| 归档时间: |
|
| 查看次数: |
1054 次 |
| 最近记录: |