前もって感謝します-私はvcrでコントローラーの仕様を記録しています。
問題:
スペックを初めて実行すると、問題なく記録されます。次に、my_spec_context_dir を削除してスペックを再実行すると、カセット ディレクトリにカセットが保存されません。
宝石:
gem 'rspec-rails', '~> 3.2.1'
gem 'webmock', '1.22.3', require: false
gem 'vcr'
gem 'capybara', '~> 2.4.3'
仕様:
#spec/controllers/my_spec.rb
require 'unit_spec_helper'
describe 'description' do
it 'example_name', :vcr do
@instance_var = table_record.attribute
get 'controller_action'
expect(response.status).to eq(200)
expect(response.content_type).to eq 'image/png'
table_record.delete
end
end
私が試したこと:
そのため、構成を調べて、実行するたびに vcr が記録する必要があることを確認します。
#spec/unit_spec_helper.rb
require 'vcr'
if Rails.env.test?
VCR.configure do |c|
c.ignore_localhost = false
c.hook_into :webmock
c.cassette_library_dir = "spec/support/cassettes"
c.configure_rspec_metadata!
c.allow_http_connections_when_no_cassette = true
c.default_cassette_options = {
allow_playback_repeats: true,
serialize_with: :json,
record: :all,
match_requests_on: [:method, :uri, :headers]
}
c.debug_logger = File.open(Rails.root.join('log/vcr.log'), 'w')
end
end
allow_playback_repeats: true, record: :all
-はい、それが私が欲しいものだと思います
vcr.log を確認すると、カセットが記録されていることがわかります。
[Cassette: 'MyController/description/example_name'] Initialized with options: {:record=>:new_episodes, :match_requests_on=>[:method, :uri, :headers], :allow_unused_http_interactions=>true, :serialize_with=>:json, :persist_with=>:file_system, :allow_playback_repeats=>true}
spec/support/cassettes
dir はまだ空なので、テストの前にキャッシュをクリアしています...Rails.cache.clear
そして再実行しています。
ディレクトリを更新するspec/support/cassettes
と、まだ空であることがわかります。.yml の保存を妨げているのは何だと思いますか?