【发布时间】:2016-01-23 22:42:37
【问题描述】:
我无法让 VCR 重新录制磁带,因此我尝试完全删除磁带,并震惊地发现我的测试套件继续通过。这怎么可能?我的理解是,卡带是用来模拟外部 API 调用的夹具。没有它们,它实际上应该点击 API 并保存一个新的磁带。这是我的vcr.rb
require 'vcr'
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr'
c.hook_into :webmock
c.default_cassette_options = { serialize_with: :json, record: :once }
c.debug_logger = File.open(Rails.root.join('log', 'vcr.log'), 'a')
c.filter_sensitive_data('---WUNDERGROUND_KEY---') { ENV['WUNDERGROUND_KEY'] }
end
这是神秘通过的测试之一:
require 'spec_helper'
describe WeatherMan do
describe ".current_outdoor_temp" do
it "returns current outdoor temperature from Wunderground API" do
VCR.use_cassette('wunderground') do
temperature = WeatherMan.current_outdoor_temp(10004, 0)
expect(temperature).to be_a Numeric
end
end
end
end
【问题讨论】:
标签: ruby-on-rails rspec vcr