我遇到了 Capybara Webkit 的问题,当我尝试运行功能规范时,它会引发以下异常。
Failure/Error: visit root_path
Capybara::Webkit::InvalidResponseError:
Unable to load URL: http://test.unbound.com:4040/ because of error loading http://test.unbound.com:4040/: Unknown error
失败的规范如下所示:
it "should render a page", js: true do
visit root_path
current_path.should == root_path
end
这是我使用:webkit_debug
驱动程序时的输出:
Run options: include {:line_numbers=>[72]}
Finished "EnableLogging" with response "Success()"
Wrote response true ""
Received "Visit"
Started "Visit"
Load started
"Visit" started page load
Started request to "http://test.unbound.com:4040/"
Finished "Visit" with response "Success()"
Received 0 from "http://test.unbound.com:4040/"
Page finished with false
Load finished
Page load from command finished
Wrote response false "{"class":"InvalidResponseError","message":"Unable to load URL: http://test.unbound.com:4040/ because of error loading http://test.unbound.com:4040/: Unknown error"}"
Received "Reset"
Started "Reset"
undefined|0|SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.
Finished "Reset" with response "Success()"
Wrote response true ""
非 JS 等效项将通过,不会引发异常。此版本使用常规 Capybara 而不是 Capybara webkit。
it "should render a page" do
visit root_path
current_path.should == root_path
end
我在每次测试之前强制主机可能是相关的,如下所示:
# default_host_and_port will equal: "test.unbound.com:4040"
default_url_options[:host] = Rails.configuration.default_host_and_port
Capybara.app_host = "http://#{Rails.configuration.default_host_and_port}"
如果我不这样做,那么我会遇到使用常规 Capybara 运行功能规范的问题。
我尝试过的一些事情:
- 在测试环境中运行服务器并
root_path
在浏览器中访问(如this SO answer中所建议)。它加载良好。将出现 JS 控制台错误,因为mixpanel
找不到,但我认为这不太可能导致问题。 - 用于
Rack::ShowExceptions
尝试获取更详细的异常。仍然得到相同的异常和回溯。 -b
使用标志运行 rspec 。没有不同。- 添加
test.unbound.com
到我的/etc/hosts
. 没有不同。 - 告诉 Capybara 忽略这样的 SSL 错误。
一条线索:
- 当我跟踪测试日志时,我从来没有看到通过的请求
GET /
。