问题
I have a test that uses OAuth2 gem to make make an HTTP request:
token = client.auth_code.get_token( code, redirect_uri:redirect_uri )
Capybara does not seem to be running the Rails app as a server:
Faraday::ConnectionFailed:
Connection refused - connect(2) for "localhost" port 3000
Here is the config:
Capybara.app_host = "http://localhost:3000"
Capybara.run_server = true
Capybara.server_port = 3000
Capybara.register_driver :rack_test do |app|
Capybara::RackTest::Driver.new app,
follow_redirects:false
end
Various docs seem to suggest that the above config will run the app as a server, but it does not seem to be the case.
How to run Capybara against a server so that the server responds to HTTP requests?
EDIT: After digging in the Capybara code, it seems that different drivers have different servers. Working with Poltergeist. So perhaps Poltergeist doesn't support running a server.
回答1:
As usual, a small detail was overlooked.
The spec must be tagged as :js
. Otherwise it uses Rack::Test and the server is not started.
来源:https://stackoverflow.com/questions/26747081/how-to-run-capybara-against-a-rails-server