加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rspec savon vcr没有录音

发布时间:2020-12-17 03:31:54 所属栏目:百科 来源:网络整理
导读:我无法用录像机录制任何内容,我有这样的设置: spec_helper.rb require 'vcr'VCR.configure do |c| c.cassette_library_dir = 'spec/cassettes' c.hook_into :webmock c.configure_rspec_metadata! c.default_cassette_options = { :record = :new_episodes
我无法用录像机录制任何内容,我有这样的设置:

spec_helper.rb

require 'vcr'
VCR.configure do |c|
  c.cassette_library_dir = 'spec/cassettes'
  c.hook_into :webmock
  c.configure_rspec_metadata!
  c.default_cassette_options = { :record => :new_episodes }
end

并测试:

describe SomeClass do
  describe '#foo',vcr: true do
    it 'should do http request',do
      expect(subject.do_request).to be_true
    end
  end
end

运行该规范会导致:

.HTTPI executes HTTP GET using the net_http adapter
SOAP request: (...)

完全像没有录像机.不幸的是documentation没有什么.我发现类似的问题报告了here,但要求httpi没有任何效果.要做到这一点应该怎么做?

解决方法

让我让VCR记录正确匹配的SOAP请求,我指定了更多的匹配器供它使用.由于使用SOAP,url端点通常是相同的,但每个请求的主体内容/标头是不同的.注意,:method,:uri,:headers.你也可以在身体上匹配,但这对我的用例来说足够了,因为我们的标题非常详细.我正在使用这个:

VCR.configure do |c|
  c.hook_into :webmock # fakeweb fails with savon
  c.ignore_hosts 'www.some-url.com'
  c.configure_rspec_metadata!
  c.ignore_localhost                        = true
  c.cassette_library_dir                    = 'spec/support/vcr_cassettes'
  c.allow_http_connections_when_no_cassette = true
  c.default_cassette_options                = { allow_playback_repeats: true,match_requests_on: [:method,:uri,:headers] }
  # c.debug_logger                            = File.open(Rails.root.join('log/vcr.log'),'w')
end

然后我用空哈希标记规范,以防我想覆盖全局VCR配置,如:

describe SomeClass do
  describe '#foo',vcr: {} do
    # test something
  end
end

最后,您可以让VCR / Webmock更多的请求忽略了更容易调试.因此,如果您有许多JS调用或类似,请将这些请求添加到’ignore_hosts’选项中.我在全局配置中的最后一行显示了如何让VCR记录它正在做的事情,也很有帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读