将 webmock 与黄瓜一起使用
我正在使用 webmock,但它不适用于黄瓜测试
在我的 Gemfile
gem 'vcr'
gem 'webmock'
和我的 features/support.env.rb 中,
require 'webmock/cucumber'
WebMock.allow_net_connect!
当我运行黄瓜测试时,我收到此错误。
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'}
我做错了什么或者缺少什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
扩展迈伦·马斯顿的答案。如果您需要为其他东西保留 localhost,例如您可能希望 VCR 捕获请求的机架应用程序,则需要创建一个自定义匹配器,而不是忽略所有 localhost 请求。
Expanding on Myron Marston's answer. If you need to keep localhost for something else, such as a Rack App, that you might want VCR to capture request for, you will need to create a custom matcher rather than ignore all localhost requests.
如果您同时使用 RSpec 和 Cucumber,则可能需要为 WebMock 创建两个配置文件(与 VCR 一起使用时):
在此处记录此文件,以便人们在谷歌搜索
__identify__
时找到。错误看起来像...If you use both RSpec and Cucumber, you might need to create two config files for WebMock (when using with VCR):
Documenting this here for people to find when googling for
__identify__
. Errors look like...首先,如果您使用的是 VCR,则无需使用
require 'webmock/cucumber'
行和WebMock.allow_net_connect!
行配置 webmock。 VCR 会为您处理任何必要的 WebMock 配置。触发错误的请求看起来像是来自 Capybara。当您使用其中一个 JavaScript 驱动程序时,水豚会使用简单的机架服务器启动您的应用程序,然后轮询特殊的 __identify__ 路径,以便它知道何时完成启动。
VCR 支持忽略本地主机请求,这样就不会干扰此操作。 relish 文档有完整的故事但简短的版本是您需要添加 VCR 配置,如下所示:
First off, if you're using VCR, you don't need to configure webmock with the
require 'webmock/cucumber'
line and theWebMock.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:
我有同样的错误,但不使用录像机。我可以通过添加以下内容来解决此问题:
到我的 env.rb 文件中。
I had the same error though do not use VCR. I was able to resolve this by adding:
to my env.rb file.