将 webmock 与黄瓜一起使用 [英] using webmock with cucumber

查看:12
本文介绍了将 webmock 与黄瓜一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 webmock,但它不适用于黄瓜测试

I am using webmock and it is not working for cucumber tests

在我的 Gemfile 中

In my Gemfile

  gem 'vcr'
  gem 'webmock'

在我的 features/support.env.rb 中,我有

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?

推荐答案

首先,如果你使用VCR,你不需要用require 'webmock/cucumber'来配置webmock行和 WebMock.allow_net_connect! 行.VCR 会为您处理任何必要的 WebMock 配置.

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.

触发错误的请求看起来像是来自 Capybara.当您使用其中一个 javascript 驱动程序时,capybara 使用简单的机架服务器启动您的应用程序,然后轮询特殊的 __identify__ 路径,以便知道何时完成启动.

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 包括对忽略 localhost 请求的支持,因此它不会对此产生干扰.relish docs 有完整的故事但简短的版本是您需要像这样添加 VCR 配置:

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 与黄瓜一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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