Skip to content

Commit 85ecd05

Browse files
koicbbatsov
authored andcommitted
Add spec for warning messages when cache location is invalid
This PR suppresses the following warnings that are displayed when running tests, and makes them executable test code. ```console % cd path/to/rubocop % bundle exec rspec ./spec/rubocop/result_cache_spec.rb:278 Run options: include {:focus=>true, :locations=>{"./spec/rubocop/result_cache_spec.rb"=>[278]}} Randomized with seed 7133 Couldn't create cache directory. Continuing without cache. Permission denied .Couldn't create cache directory. Continuing without cache. Read-only file system . Finished in 0.20314 seconds (files took 1.93 seconds to load) 2 examples, 0 failures Randomized with seed 7133 ```
1 parent e22c2e2 commit 85ecd05

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

spec/rubocop/result_cache_spec.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,33 @@ def abs(path)
271271
end
272272
end
273273

274-
shared_examples 'invalid cache location' do |error|
274+
shared_examples 'invalid cache location' do |error, message|
275+
before do
276+
$stderr = StringIO.new
277+
end
278+
275279
it 'doesn\'t raise an exception' do
276280
expect(FileUtils).to receive(:mkdir_p).with(start_with(cache_root))
277281
.and_raise(error)
278282
expect { cache.save([]) }.not_to raise_error
283+
expect($stderr.string).to eq(<<~WARN)
284+
Couldn't create cache directory. Continuing without cache.
285+
#{message}
286+
WARN
287+
end
288+
289+
after do
290+
$stderr = STDERR
279291
end
280292
end
281293

282294
context 'when the @path is not writable' do
283295
let(:cache_root) { '/permission_denied_dir' }
284296

285-
it_behaves_like 'invalid cache location', Errno::EACCES
286-
it_behaves_like 'invalid cache location', Errno::EROFS
297+
it_behaves_like 'invalid cache location',
298+
Errno::EACCES, 'Permission denied'
299+
it_behaves_like 'invalid cache location',
300+
Errno::EROFS, 'Read-only file system'
287301
end
288302
end
289303

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy