Pregunta

I'm hitting an issue with Capybara Webkit where it raises the following exception when I try to run a feature spec.

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

The failing spec looks like this:

it "should render a page", js: true do
  visit root_path
  current_path.should == root_path
end

This is the output when I use the :webkit_debug driver:

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 ""

The non-JS equivalent will pass with no exceptions raised. This version uses regular Capybara rather than Capybara webkit.

it "should render a page" do
  visit root_path
  current_path.should == root_path
end

It might be relevant that I'm forcing the host before each test like so:

# 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}"

If I don't do that then I get issues running feature specs with regular Capybara.

Some things I've tried:

  • Running the server in the test environment and visiting the root_path in the browser (as suggested in this SO answer). It loads fine. There will be a JS console error because mixpanel cannot be found but I think it is unlikely that is causing the problem.
  • Using Rack::ShowExceptions to try to get a more detailed exception. Still get the same exception and backtrace.
  • Running rspec with the -b flag. No difference.
  • Adding test.unbound.com to my /etc/hosts. No difference.
  • Telling Capybara to ignore SSL errors like this.

One clue:

  • When I tail the test log, I never see a request to GET / come through.
¿Fue útil?

Solución

The only fix is to remove host setting. That's the source of error and I see no reason you need that.

What if your tests running on a CI server or your peers' computer? They make changes to local test db but need to visit a remote server to see the changes?

Otros consejos

Have you tried putting something like this in your global rspec before(:each) block? That fixed it for me.

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top