Skip to content

Commit 9d82a03

Browse files
PauloVilarinhoPaulo Vilarinho
andauthored
add error message when cassete file does not exist (#1028)
* add error message when cassete file does not exist * add tests for all none error messages --------- Co-authored-by: Paulo Vilarinho <paulotarsobranco@gmail.com >
1 parent aff1309 commit 9d82a03

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/vcr/errors.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ def format_foot_note(url, index)
212212
"https://benoittgt.github.io/vcr/?v=%s#/record_modes/none"
213213
],
214214

215+
:none_without_file => [
216+
["The current record mode (:none) does not allow requests to be recorded.",
217+
"One or more cassette names registered was not found. Use ",
218+
":new_episodes or :once record modes to record a new cassette"],
219+
"https://benoittgt.github.io/vcr/?v=%s#/record_modes/none"
220+
],
221+
222+
215223
:use_a_cassette => [
216224
["If you want VCR to record this request and play it back during future test",
217225
"runs, you should wrap your test (or this portion of your test) in a",
@@ -284,14 +292,22 @@ def record_mode_suggestion
284292
record_modes = current_cassettes.map(&:record_mode)
285293

286294
if record_modes.all?{|r| r == :none }
287-
[:deal_with_none]
295+
none_suggestion
288296
elsif record_modes.all?{|r| r == :once }
289297
[:delete_cassette_for_once]
290298
else
291299
[]
292300
end
293301
end
294302

303+
def none_suggestion
304+
if current_cassettes.any? {|c| !File.exist?(c.file) }
305+
[:none_without_file]
306+
else
307+
[:deal_with_none]
308+
end
309+
end
310+
295311
def has_used_interaction_matching?
296312
current_cassettes.any?{|c| c.http_interactions.has_used_interaction_matching?(request) }
297313
end

spec/lib/vcr/errors_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ def request_with(options)
120120
end
121121
end
122122

123+
it 'mentions that one of the files does not exist when using :none and file does not exist' do
124+
VCR.use_cassette('example', :record => :none) do
125+
expect(message).to include('One or more cassette names registered was not found.')
126+
end
127+
end
128+
129+
it 'mentions legacy message when file exists' do
130+
VCR.configure do |c|
131+
c.cassette_library_dir = File.join(VCR::SPEC_ROOT, 'fixtures')
132+
end
133+
VCR.use_cassette('fake_example_responses', :record => :none) do
134+
expect(message).to include('can temporarily change the record mode to :once, delete the cassette file')
135+
end
136+
end
137+
123138
it 'does not mention the :once or :none record modes if using the :new_episodes record mode' do
124139
VCR.use_cassette('example', :record => :new_episodes) do
125140
expect(message).not_to include(':once', ':none')

0 commit comments

Comments
 (0)