Cucumber、Capybara、Rails 3、302 发现重定向问题
我是水豚的新手,但我正在尝试用它来测试(使用黄瓜)我正在从 Rails 2 转换为 Rails 3 的应用程序。但是,在测试登录时我遇到了奇怪的行为。我有一个黄瓜登录步骤以下:
visit login_path
fill_in 'Email', :with => '[email protected]'
fill_in 'Password', :with => 'XXXXXXXXX'
click_button 'Log in'
当此自定义步骤运行时,黄瓜给出以下错误:
<块引用>找不到 UserSessionsController 的操作“index”
AbstractController::ActionNotFound)
日志输出以下内容:
Started GET "/login" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#new as HTML
Redirected to https://www.example.com/login
Completed 302 Found in 1ms
Started GET "/login" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#new as HTML
Rendered user_sessions/new.html.erb within layouts/promo (15.8ms)
Completed 200 OK in 38ms (Views: 24.5ms | ActiveRecord: 2.9ms)
Started POST "/user_sessions" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#create as HTML
Parameters: {"commit"=>"Log in", "user_session"=>{"password"=>"[FILTERED]", "email"=>"[email protected]"}, "utf8"=>"✓"}
Redirected to https://www.example.com/user_sessions
Completed 302 Found in 1ms
Started GET "/user_sessions" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
SQL (0.6ms) ROLLBACK
所以这是我的问题:
为什么/login GET然后重定向到/login???
为什么到 /user_sessions 的 POST 也被重定向到自身(这会导致我看到的错误)???
在开发中一切都工作得很好,我没有看到 302 状态代码。这可能很简单,但我不明白。
编辑: 提交此内容 5 分钟后,我意识到是 SSL_requirement 插件导致了重定向。当我注释掉“ssl_required”时,测试通过。我将不得不对 Capybara 进行更多研究,以找出如何配置它,除非有人给出答案。
编辑答案(因为它不允许我在 8 小时内发布答案): 我找到了答案。正如我在编辑中所述,问题是由于 SSL 要求而导致的重定向。可以在这里找到对该问题的很好的描述: https://github.com/jnicklas/capybara /issues/85。当前的解决方案是一个对我有用的补丁,可以在这里找到: https://gist.github.com/466411 。
I am new to capybara but I am trying to use it to test (with cucumber) an app I am converting from rails 2 to rails 3. However, I am getting strange behavior when testing log in. I have a cucumber login step that does the following:
visit login_path
fill_in 'Email', :with => '[email protected]'
fill_in 'Password', :with => 'XXXXXXXXX'
click_button 'Log in'
When this custom step runs cucumber gives me the following error:
The action 'index' could not be found for UserSessionsController
AbstractController::ActionNotFound)
And the log outputs the following:
Started GET "/login" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#new as HTML
Redirected to https://www.example.com/login
Completed 302 Found in 1ms
Started GET "/login" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#new as HTML
Rendered user_sessions/new.html.erb within layouts/promo (15.8ms)
Completed 200 OK in 38ms (Views: 24.5ms | ActiveRecord: 2.9ms)
Started POST "/user_sessions" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#create as HTML
Parameters: {"commit"=>"Log in", "user_session"=>{"password"=>"[FILTERED]", "email"=>"[email protected]"}, "utf8"=>"✓"}
Redirected to https://www.example.com/user_sessions
Completed 302 Found in 1ms
Started GET "/user_sessions" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
SQL (0.6ms) ROLLBACK
So here are my questions:
Why is the /login GET and then redirected to /login???
Why is the POST to /user_sessions also getting redirected to itself (which causes the error I see)???
Everything works perfectly fine in development and I see no 302 status codes. It may be something simple but I don't see it.
EDIT:
5 min after submitting this I realized it was the SSL_requirement plugin causing the redirects. When I comment out "ssl_required", the tests pass. I will have to do more research into Capybara to find out how to configure it unless someone comes up with an answer.
EDIT ANSWER (since it won't let me post one for 8 hours):
I found the answer. As I stated in my edit, the issue is the redirection due to SSL requirement. A very good description of the problem can be found here: https://github.com/jnicklas/capybara/issues/85. The current solution is a patch which worked for me that can be found here: https://gist.github.com/466411.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案。正如我在编辑中所述,问题是由于 SSL 要求而导致的重定向。可以在这里找到对该问题的很好的描述: https://github.com/jnicklas/capybara /issues/85。当前的解决方案是一个对我有用的补丁,可以在这里找到: https://gist.github.com/466411 。
I found the answer. As I stated in my edit, the issue is the redirection due to SSL requirement. A very good description of the problem can be found here: https://github.com/jnicklas/capybara/issues/85. The current solution is a patch which worked for me that can be found here: https://gist.github.com/466411.