我有一些Cucumber功能,需要与Google Maps Routing API进行交互。我正在尝试使用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__
最佳答案
您必须将VCR设置为ignore localhost requests。否则,当 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
关于testing - 通过标签将VCR与Cucumber一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8148168/