我在互联网上搜索了这个问题的答案,包括大多数其他“建议”的问题。
我已经在rspec中配置了VCR,但是在运行测试时,VCR从不记录磁带(磁带dir保持为空),并且每次运行HTTP请求。
我的VCR配置如下所示:
VCR.configure do |c|
c.cassette_library_dir = Rails.root.join('spec', 'vcr_cassettes')
c.hook_into :faraday
c.default_cassette_options = { record: :new_episodes }
c.configure_rspec_metadata!
c.allow_http_connections_when_no_cassette = true
c.ignore_hosts 'api.linkedin.com'
c.debug_logger = $stderr
end我使用faraday是因为我使用的LinkedIn gem (https://github.com/bobbrez/linkedin2)已经在使用faraday来发出请求了。我正在运行的测试规范如下所示:
describe API::V1::Connections, type: :request do
subject { LinkedIn::Client.new scope: %i(r_network) }
describe 'GET /api/v1/connections/:username', vcr: { cassette_name: 'profile' } do
it 'fetches the user profile' do
profile = subject.profile
expect(profile).not_to be_nil
end
end
end它每次都会传递,但每次都是在发出API请求之后。VCR调试日志显示与规范每次运行的完全相同:
[Cassette: 'profile'] Initialized with options: {:record=>:new_episodes, :match_requests_on=>[:method, :uri, :headers], :allow_unused_http_interactions=>true, :serialize_with=>:yaml, :persist_with=>:file_system}
[faraday] Handling request: [get https://api.linkedin.com/v1/people/~:(connections)?oauth2_access_token=xxxx&format=json {"User-Agent"=>["Faraday v0.9.0"]}] (disabled: false)
[faraday] Identified request type (ignored) for [get https://api.linkedin.com/v1/people/~:(connections)?oauth2_access_token=xxxx&format=json {"User-Agent"=>["Faraday v0.9.0"]}]它似乎应该录制一个盒式磁带,但是.yml文件从来没有出现在spec/vcr_cassettes dir中。
(使用Rails 4、rspec 3、vcr 2.9)
发布于 2014-06-20 06:46:54
您已经将录像机配置为忽略使用以下行向'api.linkedin.com'发出的请求:
c.ignore_hosts 'api.linkedin.com'...which阻止它记录这些请求。
https://stackoverflow.com/questions/24291345
复制相似问题