Skip to content

Commit

Permalink
Fix the behavior of the option re_record_interval (vcr#824)
Browse files Browse the repository at this point in the history
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 vcr#687
  • Loading branch information
nicolasiensen authored Jul 14, 2020
1 parent 5c57aa5 commit 33757df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/vcr/cassette.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions spec/lib/vcr/cassette_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 33757df

Please sign in to comment.