5

我有一些需要与 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

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__
4

1 回答 1

12

您必须将 VCR 设置为忽略 localhost 请求。否则,当 capybara 尝试从您的网站请求任何页面时,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
于 2011-11-16T07:40:18.267 回答