2011-11-16 79 views
5

我有一些需要与Google Maps Routing API交互的Cucumber功能。我正在尝试使用VCR来删除这些交互。通过标签对黄瓜使用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 

加入我的VCR的配置,但是当我运行我cukes,有人告诉我..

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

回答

12

您必须将录像机设置为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 
+3

FWIW,问题(和解决方案)与黄瓜无关。它与水豚有关,它可以启动你的应用程序,并在使用JavaScript驱动程序时向它发出请求。如果您使用Test :: Unit或RSpec使用水豚,您会遇到同样的问题。 –