问题描述
我正在使用webmock,它不适用于黄瓜测试
在我的Gemfile中
gem'vcr'
gem'webmock'
我的功能/ support.env.rb,我有
require'webmock / cucumber'
WebMock.allow_net_connect!
当我运行我的黄瓜测试,我得到这个错误。
实际的HTTP连接被禁用。未注册的请求:
GET http://127.0.0.1:9887/__identify__ with headers
{'Accept'=>'* / *','Accept-Encoding'=>'gzip; q = 1.0,deflate; q = 0.6,identity; q = 0.3','User-Agent'=>'Ruby'}
我做错了什么或是sth丢了?
首先,如果你使用VCR,你不需要配置webmock与 require'webmock / cucumber'
行和 WebMock.allow_net_connect!
line。 VCR会为您处理任何必要的WebMock配置。
触发错误的请求看起来像是来自Capybara。当您使用其中一个javascript驱动程序时,capybara使用简单的机架服务器启动您的应用程序,然后轮询特殊的 __ identify __
路径,以便它知道什么时候完成启动。 p>
VCR包括忽略localhost请求的支持,因此它不会干扰此。 有完整的故事但简短的版本是,你需要添加VCR配置如下:
VCR.config do | c |
c.ignore_localhost = true
end
I am using webmock and it is not working for cucumber tests
In my Gemfile
gem 'vcr'
gem 'webmock'
And in my features/support.env.rb, I have
require 'webmock/cucumber'
WebMock.allow_net_connect!
When I run my cucumber tests I am getting this error.
Real HTTP connections are disabled. Unregistered request:
GET http://127.0.0.1:9887/__identify__ with headers
{'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}
Am I doing anything wrong or is sth missing?
First off, if you're using VCR, you don't need to configure webmock with the require 'webmock/cucumber'
line and the WebMock.allow_net_connect!
line. VCR takes care of any necessary WebMock configuration for you.
The request that is triggering the error looks like it's coming from Capybara. When you use one of the javascript drivers, capybara boots your app using a simple rack server, and then polls the special __identify__
path so it knows when it has finished booting.
VCR includes support for ignoring localhost requests so that it won't interfere with this. The relish docs have the full story but the short version is that you need to add VCR configuration like this:
VCR.config do |c|
c.ignore_localhost = true
end
这篇关于使用webmock用黄瓜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!