gpt4 book ai didi

ruby-on-rails - Webrat 和 Rails : Using assert_contain after click_button gives me "You are being redirected"

转载 作者:行者123 更新时间:2023-12-04 05:28:36 24 4
gpt4 key购买 nike

我正在使用 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,所以我在这里遗漏了一些明显的东西吗?为什么我坚持重定向响应?

谢谢!

黛布

最佳答案

对于一个新的 Rails 3 应用程序,我在测试一个简单的方法时也遇到了这个问题,该方法在 Controller 中包含了一个 redirect_to 调用。该方法本身运行良好,但 Webrat 会返回“您正在被重定向”。回复。

在 Cucumber 中添加“然后向我显示页面”步骤(因此 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 现在可以正常工作。

关于ruby-on-rails - Webrat 和 Rails : Using assert_contain after click_button gives me "You are being redirected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2974330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com