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

时间:2011-11-16 07:37:59

标签: testing cucumber bdd 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"

然后在features/support/vcr.rb

中添加了我的VCR配置
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

但是,当我发现我的傻瓜时,我被告知......

Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:54181/__identify__

1 个答案:

答案 0 :(得分:12)

您必须将VCR设置为ignore localhost requests。否则,当水豚尝试从您的网站请求任何页面时,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