From 33757dfc6cabc1204e7a209676dfee9b098133d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcolas=20Iensen?= Date: Tue, 14 Jul 2020 10:52:02 +0200 Subject: [PATCH] Fix the behavior of the option re_record_interval (#824) In this commit, we are changing how the option re_record_interval behaves. If this option is provided together with record mode set to none, VCR won't re-record cassettes, even if their intervals have expired. Fixes #687 --- lib/vcr/cassette.rb | 6 +++--- spec/lib/vcr/cassette_spec.rb | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/vcr/cassette.rb b/lib/vcr/cassette.rb index d9272908..6b9ef1a2 100644 --- a/lib/vcr/cassette.rb +++ b/lib/vcr/cassette.rb @@ -192,10 +192,9 @@ def extract_options assign_tags - @record_mode = @options[:record] @serializer = VCR.cassette_serializers[@options[:serialize_with]] @persister = VCR.cassette_persisters[@options[:persist_with]] - @record_mode = :all if should_re_record? + @record_mode = should_re_record?(@options[:record]) ? :all : @options[:record] @parent_list = @exclusive ? HTTPInteractionList::NullList : VCR.http_interactions end @@ -231,9 +230,10 @@ def raise_error_unless_valid_record_mode end end - def should_re_record? + def should_re_record?(record_mode) return false unless @re_record_interval return false unless originally_recorded_at + return false if record_mode == :none now = Time.now diff --git a/spec/lib/vcr/cassette_spec.rb b/spec/lib/vcr/cassette_spec.rb index ca5fc44b..ded81737 100644 --- a/spec/lib/vcr/cassette_spec.rb +++ b/spec/lib/vcr/cassette_spec.rb @@ -320,9 +320,16 @@ def stub_old_interactions(interactions) Time.now - 5.days - 60 ] end - it "has :all for the record mode when there is an internet connection available" do - allow(VCR::InternetConnection).to receive(:available?).and_return(true) - expect(subject.record_mode).to eq(:all) + if record_mode == :none + it "has :none for the record mode when there is an internet connection available" do + allow(VCR::InternetConnection).to receive(:available?).and_return(true) + expect(subject.record_mode).to eq(:none) + end + else + it "has :all for the record mode when there is an internet connection available" do + allow(VCR::InternetConnection).to receive(:available?).and_return(true) + expect(subject.record_mode).to eq(:all) + end end it "has :#{record_mode} for the record mode when there is no internet connection available" do