Ruby on rails 录像机不使用法拉第录音带
我已经在互联网上搜索了这个问题的答案,包括大多数其他的“建议”问题 我已经在rspec中配置了VCR,但在运行测试时,VCR从不记录磁带(磁带目录仍然为空),每次都运行HTTP请求 我的VCR配置如下所示:Ruby on rails 录像机不使用法拉第录音带,ruby-on-rails,ruby-on-rails-4,rspec,faraday,vcr,Ruby On Rails,Ruby On Rails 4,Rspec,Faraday,Vcr,我已经在互联网上搜索了这个问题的答案,包括大多数其他的“建议”问题 我已经在rspec中配置了VCR,但在运行测试时,VCR从不记录磁带(磁带目录仍然为空),每次都运行HTTP请求 我的VCR配置如下所示: VCR.configure do |c| c.cassette_library_dir = Rails.root.join('spec', 'vcr_cassettes') c.hook_into :faraday c.default_cassette_options = { r
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
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
我正在使用faraday
,因为我正在使用的LinkedIn gem()已经在使用faraday
发出请求了。我正在运行的测试规范如下所示:
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
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"]}]
它似乎应该录制磁带,但在spec/vcr\u磁带
dir中从来没有出现.yml
文件
(使用Rails 4、rspec 3、vcr 2.9)您已将vcr配置为忽略对
'api.linkedin.com'
发出的请求,行为:
c.ignore_hosts 'api.linkedin.com'
…这会阻止它记录这些请求。您已将VCR配置为忽略对
'api.linkedin.com'
发出的请求,行为:
c.ignore_hosts 'api.linkedin.com'
…这会阻止它记录这些请求。您已将VCR配置为忽略对
'api.linkedin.com'
发出的请求,行为:
c.ignore_hosts 'api.linkedin.com'
…这会阻止它记录这些请求。您已将VCR配置为忽略对
'api.linkedin.com'
发出的请求,行为:
c.ignore_hosts 'api.linkedin.com'
…这会阻止它记录这些请求。是的,出于某种原因,我的印象是“忽略主机”选项只允许对该URL的请求。显然我读得不够仔细。谢谢你指出这一点。是的,出于某种原因,我觉得ignore_hosts选项只允许对该URL的请求。显然我读得不够仔细。谢谢你指出这一点。是的,出于某种原因,我觉得ignore_hosts选项只允许对该URL的请求。显然我读得不够仔细。谢谢你指出这一点。是的,出于某种原因,我觉得ignore_hosts选项只允许对该URL的请求。显然我读得不够仔细。谢谢你指出这一点。