Ruby VCR-gem在录制可用时禁用重新录制



我想记录一次API响应,并永久使用,但VCR似乎想在一段时间后重新记录。

我试着在谷歌上搜索如何禁用它。找到了re_record_interval,但它似乎不起作用。

我当前的VCS设置是spec/support/vcr_setup.rb

# frozen_string_literal: true
VCR.configure do |c|
c.cassette_library_dir = 'spec/vcr'
c.hook_into :webmock
c.configure_rspec_metadata!
c.allow_http_connections_when_no_cassette = false
c.default_cassette_options = {
record: :none,
re_record_interval: nil,
match_requests_on: %i[method uri],
allow_playback_repeats: true
}
c.debug_logger = $stdout
end

这是VCR-的调试日志

[Cassette: 'some-name./1:1:6:2:1:1'] Initialized with options: {:record=>:none, :record_on_error=>true, :match_requests_on=>[:method, :uri], :allow_unused_http_interactions=>true, :serialize_with=>:yaml, :persist_with=>:file_system, :re_record_interval=>nil, :allow_playback_repeats=>true}
Scraping url: some-url
[webmock] Handling request: [get some-url] (disabled: false)
[Cassette: 'some-name/1:1:6:2:1:1'] Initialized HTTPInteractionList with request matchers [:method, :uri] and 0 interaction(s): {  }
[webmock] Identified request type (unhandled) for [get some-url]

注意:有一个录制的文件在一个小时前得到了它,但现在VCR正在尝试一个新的HTTP请求并创建一个新记录文件。

经过一些调试,发现vcr文件名实际上是rpcec作用域id。您可以在此处查看rspec元数据,了解作用域id的样子。https://www.tutorialspoint.com/rspec/rspec_metadata.htm

scope_id类似于"1:1:6:2:1:1",意思是第一块>第一块>第六块,依此类推。你明白了。

这意味着,如果更改等级库文件中块的顺序,也会更改记录的文件。

最新更新