Webrat和Rails:在click_button之后使用assert_contain会给我“您正在重定向", [英] Webrat and Rails: Using assert_contain after click_button gives me "You are being redirected"

查看:78
本文介绍了Webrat和Rails:在click_button之后使用assert_contain会给我“您正在重定向",的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用webrat编写针对Rails应用程序的集成测试.填写表单后,用户按Submit(提交),然后创建一个帐户.

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"

但是,测试失败:

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应该可以工作

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

我刚刚开始使用Webrat,所以我在这里遗漏了明显的东西吗?为什么我坚持使用重定向响应?

I just started using Webrat, so am I missing something obvious here? Why am I stuck with the redirect response?

谢谢!

Deb

推荐答案

在使用新的Rails 3应用程序时,我还遇到了测试简单方法的问题,该方法包括控制器中的redirect_to调用.该方法本身可以正常工作,但是Webrat会返回您正在被重定向".响应.

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.

在黄瓜中添加然后向我展示页面"步骤(这样webrat看到的页面将在浏览器中打开)显示了您正在重定向."响应,并带有指向example.org链接的链接.

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.

基于此,我发现了Yannimac的补丁程序( http://groups.google .com/group/webrat/browse_thread/thread/fb5ff3fccd97f3df ):

Based on this I discovered Yannimac's patch ( http://groups.google.com/group/webrat/browse_thread/thread/fb5ff3fccd97f3df ):

#/lib/webrat/core/session.rb
#starting at line 288

def current_host
- URI.parse(current_url).host || @custom_headers["Host"] || "www.example.com"
+ URI.parse(current_url).host || @custom_headers["Host"] || default_current_host
end

+ def default_current_host
+   adapter.class==Webrat::RackAdapter ? "example.org" : "www.example.com"
+ end 

进行这些更改可解决此问题,因此Webrat的redirect_to调用现在可以正常工作.

Making these changes fixed the issue, so redirect_to calls with Webrat now work correctly.

这篇关于Webrat和Rails:在click_button之后使用assert_contain会给我“您正在重定向",的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆