deb*_*deb 8 ruby-on-rails webrat
我正在使用webrat为rails应用程序编写集成测试.填写表单后,用户按下提交并创建一个帐户.
click_button "Submit"
assert_contain "Your Account Has Been Created"
Run Code Online (Sandbox Code Playgroud)
但是,测试失败:
expected the following element's content to include "Your Account Has Been Created":
You are being redirected.
<false> is not true.
Run Code Online (Sandbox Code Playgroud)
通常要遵循重定向我会使用post_via_redirect,但仅仅看一下Webrat的例子,click_button后跟assert_contain应该工作
我刚刚开始使用Webrat,所以我错过了一些明显的东西吗?为什么我坚持使用重定向响应?
谢谢!
德布
jus*_*see 11
使用新的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
Run Code Online (Sandbox Code Playgroud)
进行这些更改可以解决问题,因此使用Webrat的redirect_to调用现在可以正常工作.
| 归档时间: |
|
| 查看次数: |
2919 次 |
| 最近记录: |