How to run Capybara against a Rails server?

删除回忆录丶 提交于 2019-12-13 04:44:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!