我正在使用webmock,它不适用于黄瓜测试
在我的Gemfile中
gem 'vcr'
gem 'webmock'在我的feature/support.env.rb中,我有
require 'webmock/cucumber'
WebMock.allow_net_connect!当我运行我的cucumber测试时,我得到了这个错误。
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'}是我做错了什么还是遗漏了什么?
发布于 2011-05-25 14:05:33
首先,如果你使用的是录像机,你不需要配置webmock的require 'webmock/cucumber'行和WebMock.allow_net_connect!行。录像机会为您处理任何必要的WebMock配置。
触发错误的请求看起来像是来自Capybara。当你使用javascript驱动程序时,capybara使用一个简单的机架服务器引导你的应用程序,然后轮询特殊的__identify__路径,这样它就知道什么时候完成了引导。
VCR包括对忽略本地主机请求的支持,这样它就不会干扰这一点。relish docs有完整的故事,但简短的版本是你需要像这样添加录像机配置:
VCR.config do |c|
c.ignore_localhost = true
end发布于 2013-01-08 04:41:46
我有相同的错误,但不要使用录像机。我可以通过添加以下内容来解决此问题:
require 'webmock/cucumber'
WebMock.disable_net_connect!(:allow_localhost => true)添加到我的env.rb文件。
发布于 2013-11-15 06:10:19
在Myron Marston's answer上扩展。如果您需要为其他东西保留localhost,例如机架应用程序,您可能希望VCR捕获请求,您将需要创建自定义匹配器,而不是忽略所有的localhost请求。
require 'vcr'
VCR.configure do |c|
c.hook_into :webmock
c.ignore_localhost = false
c.ignore_request do |request|
localhost_has_identify?(request)
end
end
private
def localhost_has_identify?(request)
if(request.uri =~ /127.0.0.1:\d{5}\/__identify__/)
true
else
false
end
endhttps://stackoverflow.com/questions/6119669
复制相似问题