首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VCR不使用faraday记录磁带

VCR不使用faraday记录磁带
EN

Stack Overflow用户
提问于 2014-06-18 17:04:58
回答 1查看 2K关注 0票数 0

我在互联网上搜索了这个问题的答案,包括大多数其他“建议”的问题。

我已经在rspec中配置了VCR,但是在运行测试时,VCR从不记录磁带(磁带dir保持为空),并且每次运行HTTP请求。

我的VCR配置如下所示:

代码语言:javascript
复制
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来发出请求了。我正在运行的测试规范如下所示:

代码语言:javascript
复制
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调试日志显示与规范每次运行的完全相同:

代码语言:javascript
复制
[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)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-20 06:46:54

您已经将录像机配置为忽略使用以下行向'api.linkedin.com'发出的请求:

代码语言:javascript
复制
c.ignore_hosts 'api.linkedin.com'

...which阻止它记录这些请求。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24291345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档