如何在Rails服务器上运行Capybara? [英] How to run Capybara against a Rails server?

查看:77
本文介绍了如何在Rails服务器上运行Capybara?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用OAuth2 gem发出HTTP请求的测试:

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似乎没有将Rails应用程序作为服务器运行:

Capybara does not seem to be running the Rails app as a server:

Faraday::ConnectionFailed:
   Connection refused - connect(2) for "localhost" port 3000

这里是配置:

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.

如何在服务器上运行Capybara,以便服务器响应HTTP请求?

How to run Capybara against a server so that the server responds to HTTP requests?

编辑:在Capybara代码中进行挖掘之后,似乎不同的驱动程序具有不同的服务器。与Poltergeist合作。因此,也许Poltergeist不支持运行服务器。

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.

推荐答案

像往常一样,忽略了一个小细节。

As usual, a small detail was overlooked.

该规范必须标记为:js 。否则,它将使用Rack :: Test并且服务器不会启动。

The spec must be tagged as :js. Otherwise it uses Rack::Test and the server is not started.

这篇关于如何在Rails服务器上运行Capybara?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆