Webrat 和 Rails:在 click_button 之后使用 assert_contain 会给我“您正在被重定向”
我正在使用 webrat 为 Rails 应用程序编写集成测试。填写表格后,用户按下提交并创建一个帐户。
click_button "Submit"
assert_contain "Your Account Has Been Created"
然而,测试失败了:
expected the following element's content to include "Your Account Has Been Created":
You are being redirected.
<false> is not true.
通常要遵循重定向,我会使用 post_via_redirect,但是从仅查看 Webrat 的示例来看,click_button 后接assert_contain 应该可以工作
我刚刚开始使用 Webrat,所以我在这里遗漏了一些明显的东西吗?为什么我被重定向响应困住了?
谢谢!
德布
I'm writing an integration test for a rails application using webrat. After filling out a form, the user presses submit and an account is created.
click_button "Submit"
assert_contain "Your Account Has Been Created"
However, the test fails:
expected the following element's content to include "Your Account Has Been Created":
You are being redirected.
<false> is not true.
Normally to follow a redirect I would use post_via_redirect, but from just looking at Webrat's examples, click_button followed by assert_contain should work
I just started using Webrat, so am I missing something obvious here? Why am I stuck with the redirect response?
Thanks!
Deb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的应用程序中有任何身份验证吗?我认为重定向是因为您尚未经过身份验证。如果我的假设是正确的,请编写一个首先使用 Webrat 登录的设置。
Do you have any authentication in your apps? I presume the redirection is because of you have not been authenticated. If my assumption is right, write a setup to login first with Webrat.
以下是解决此问题所需执行的要点。
https://gist.github.com/752766
Here is the gist with exactly what you need to do to solve this problem.
https://gist.github.com/752766
使用新的 Rails 3 应用程序时,我在测试一个简单的方法时也遇到了这个问题,该方法包括控制器中的redirect_to 调用。该方法本身运行良好,但 Webrat 会返回“您正在被重定向”。回复。
在 Cucumber 中添加“然后向我显示页面”步骤(以便 webrat 看到的页面在浏览器中打开)显示“您正在被重定向。”响应,其中包含指向 example.org 链接的链接。
基于此,我发现Yannimac 的补丁 ( http://groups.google.com/group/webrat/browse_thread /thread/fb5ff3fccd97f3df ):
进行这些更改解决了问题,因此使用 Webrat 进行的redirect_to 调用现在可以正常工作。
With a new Rails 3 app, I also had this problem testing a simple method which included a redirect_to call in the controller. The method itself worked fine, but Webrat would return the "You are being redirected." response.
Adding in a 'Then show me the page' step in cucumber (so the page that webrat sees opens in the browser) showed the 'You are being redirected." response with a link to an example.org link.
Based on this I discovered Yannimac's patch ( http://groups.google.com/group/webrat/browse_thread/thread/fb5ff3fccd97f3df ):
Making these changes fixed the issue, so redirect_to calls with Webrat now work correctly.
Rails 3 和 webrat 存在一些问题。请参阅:
http://baldowl。 github.com/2010/12/06/coercing-cucumber-and-webrat-to-cooperate.html
There are some issues with rails 3 and webrat. Please see:
http://baldowl.github.com/2010/12/06/coercing-cucumber-and-webrat-to-cooperate.html