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.  is not true. 

通常要遵循重定向我会使用post_via_redirect,但仅仅看一下Webrat的例子,click_button后跟assert_contain应该有效

我刚刚开始使用Webrat,所以我错过了一些明显的东西吗? 为什么我坚持使用重定向响应?

谢谢!

德布

使用新的Rails 3应用程序,我也遇到了这个问题,测试了一个简单的方法,其中包括控制器中的redirect_to调用。 该方法本身工作正常,但Webrat将返回“你被重定向”。 响应。

在黄瓜中添加“然后显示页面”步骤(因此webrat看到的页面在浏览器中打开)显示“您正被重定向。”响应以及指向example.org链接的链接。

基于此,我发现了Yannimac的补丁( 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调用现在可以正常工作。

您的应用中是否有任何身份validation? 我认为重定向是因为你没有经过身份validation。 如果我的假设是正确的,请首先使用Webrat编写登录设置。

以下是您需要做的就是解决这个问题的要点。

https://gist.github.com/752766