通过标签使用带有黄瓜的VCR

Dav*_*ite 5 testing bdd cucumber vcr

我有一些需要与Google Maps Routing API交互的Cucumber功能.我正在尝试使用VCR来消除这些交互.

我在我的功能中添加了一个VCR标签,如下所示:

@google_routing_api @javascript
Scenario: Creating a bus
  Given I am on the buses page
  When I follow "Get Started Now"
Run Code Online (Sandbox Code Playgroud)

然后添加了我的VCR配置 features/support/vcr.rb

require 'vcr'

VCR.config do |c|
  # INFO: This is relative to the Rails.root
  c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
  c.stub_with :fakeweb
end

# INFO: https://github.com/myronmarston/vcr/wiki/Usage-with-Cucumber
VCR.cucumber_tags do |t|
  t.tag '@google_routing_api'
end
Run Code Online (Sandbox Code Playgroud)

但是当我举起我的傻瓜时,我被告知......

Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:54181/__identify__
Run Code Online (Sandbox Code Playgroud)

Dav*_*ite 12

您必须将VCR设置为忽略localhost请求.否则,当水豚尝试从您的网站请求任何页面时,VCR将阻止它.

添加c.ignore_localhost = true到您的VCR配置块.

VCR.config do |c|
  c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
  c.stub_with :fakeweb
  c.ignore_localhost = true
end
Run Code Online (Sandbox Code Playgroud)

  • FWIW,问题(和解决方案)与黄瓜无关.它与capybara以及它启动你的app并在你使用javascript驱动程序时向它发出请求的事实有关.如果你使用带有Test :: Unit或RSpec的水豚,你会遇到同样的问题. (3认同)