Ruby on rails Capybara Webkit引发了无效响应者”的问题;无法加载URL";

Ruby on rails Capybara Webkit引发了无效响应者”的问题;无法加载URL";,ruby-on-rails,ruby,rspec,capybara,capybara-webkit,Ruby On Rails,Ruby,Rspec,Capybara,Capybara Webkit,我遇到了一个关于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 失败的规范如

我遇到了一个关于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等效项将通过,不会引发异常。此版本使用常规水豚而不是水豚网络工具包

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}"
如果我不这样做,那么我就会在运行常规水豚的特性规范时遇到问题

我尝试过的一些事情:

  • 在测试环境中运行服务器并访问浏览器中的
    根路径
    (如中所建议)。很好。将出现JS控制台错误,因为找不到
    mixpanel
    ,但我认为这不太可能是导致问题的原因
  • 使用
    Rack::ShowExceptions
    尝试获取更详细的异常。仍然得到相同的异常和回溯
  • 使用
    -b
    标志运行rspec。没有区别
  • test.unbound.com
    添加到我的
    /etc/hosts
    。没有区别
  • 告诉水豚忽略SSL错误
一条线索:

  • 当我跟踪测试日志时,我从未看到
    GET/
    的请求通过

唯一的修复方法是删除主机设置。这是错误的根源,我看你没有理由需要它


如果您的测试运行在CI服务器或您的对等计算机上,该怎么办?他们对本地测试数据库进行了更改,但需要访问远程服务器才能查看更改?

您是否尝试在(:each)块之前的全局rspec中添加类似的内容?那帮我修好了

RSpec.configure do |config|
  config.before(:each) do
    if Capybara.javascript_driver == :webkit
      # Allow loading of all external URLs
      page.driver.allow_url("*")
      # Ignore SSL errors
      page.driver.browser.ignore_ssl_errors
    end
  end
end

您认为删除将解决当前问题是正确的。它引入了一个问题,即当请求在应用程序中的SSL和非SSL页面之间重定向时,Cookie会丢失。不过我想这是另一个问题。大卫,是的,这确实是另一个问题:)嗨,比利,我在使用@javascriptundefined方法'allow_url'时遇到了cucumber的同样问题#