2011-11-16 55 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使用水豚,您會遇到同樣的問題。 –