Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #734: Add fail_on_re_record option, to raise an exception when cassette re-recorded #768

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/vcr/cassette.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def assert_valid_options!
:record, :record_on_error, :erb, :match_requests_on, :re_record_interval, :tag, :tags,
:update_content_length_header, :allow_playback_repeats, :allow_unused_http_interactions,
:exclusive, :serialize_with, :preserve_exact_body_bytes, :decode_compressed_response,
:recompress_response, :persist_with, :clean_outdated_http_interactions
:recompress_response, :persist_with, :clean_outdated_http_interactions, :fail_on_re_record
]

if invalid_options.size > 0
Expand All @@ -186,7 +186,7 @@ def assert_valid_options!

def extract_options
[:record_on_error, :erb, :match_requests_on, :re_record_interval, :clean_outdated_http_interactions,
:allow_playback_repeats, :allow_unused_http_interactions, :exclusive].each do |name|
:allow_playback_repeats, :allow_unused_http_interactions, :exclusive, :fail_on_re_record].each do |name|
instance_variable_set("@#{name}", @options[name])
end

Expand Down Expand Up @@ -243,7 +243,11 @@ def should_re_record?
if !value
log "Not re-recording since the interval has not elapsed (#{info})."
elsif InternetConnection.available?
log "re-recording (#{info})."
if @fail_on_re_record
raise RuntimeError.new("Beyond record interval. Please re_record your cassette and commit them.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise RuntimeError.new("Beyond record interval. Please re_record your cassette and commit them.")
raise RuntimeError.new("The re-record interval has passed, please re_record your cassettes.")

else
log "re-recording (#{info})."
end
else
log "Not re-recording because no internet connection is available (#{info})."
return false
Expand Down
10 changes: 8 additions & 2 deletions spec/lib/vcr/cassette_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ def stub_old_interactions(interactions)

context "and re_record_interval is 7.days" do
let(:file_name) { ::File.join(VCR.configuration.cassette_library_dir, "cassette_name.yml") }
subject { VCR::Cassette.new(::File.basename(file_name).gsub('.yml', ''), :record => record_mode, :re_record_interval => 7.days) }
let(:fail_on_re_record_option) {false}
subject { VCR::Cassette.new(::File.basename(file_name).gsub('.yml', ''), :record => record_mode, :re_record_interval => 7.days, fail_on_re_record: fail_on_re_record_option )}

context 'when the cassette file does not exist' do
before(:each) { allow(::File).to receive(:exist?).with(file_name).and_return(false) }
Expand Down Expand Up @@ -319,7 +320,12 @@ def stub_old_interactions(interactions)
Time.now - 7.days - 60,
Time.now - 5.days - 60
] end

context "config option fail_on_re_record is set to true on re_record" do
let(:fail_on_re_record_option) {true}
it "raises an error" do
expect{subject}.to raise_error("Beyond record interval. Please re_record your cassette and commit them.")
end
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)
Expand Down