Skip to content

Commit

Permalink
Fix RSpec/StubbedMock offenses
Browse files Browse the repository at this point in the history
I know that the RSpec/StubbedMock cop can be controversial, and I didn't
want to enable it and *always* enforce its recommended style.

But in all three cases this cop finds in our spec suite, the mock
(defined by `expect`) is entirely unnecessary - using a stub (with
`allow`) is enough. If any of the stubs are changed, other expectations
in each example will fail.
  • Loading branch information
bquorning authored and bbatsov committed Feb 14, 2021
1 parent fcb3a94 commit 708eb90
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions spec/rubocop/result_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def abs(path)
context 'when team external_dependency_checksum changes' do
it 'is invalid' do
cache.save(offenses)
expect(team).to(
allow(team).to(
receive(:external_dependency_checksum).and_return('bar')
)
cache2 = described_class.new(
Expand All @@ -188,7 +188,7 @@ def abs(path)
context 'when team external_dependency_checksum is the same' do
it 'is valid' do
cache.save(offenses)
expect(team).to(
allow(team).to(
receive(:external_dependency_checksum).and_return('foo')
)
cache2 = described_class.new(
Expand Down Expand Up @@ -329,8 +329,8 @@ def abs(path)
end

it 'doesn\'t raise an exception' do
expect(FileUtils).to receive(:mkdir_p).with(start_with(cache_root))
.and_raise(error)
allow(FileUtils).to receive(:mkdir_p).with(start_with(cache_root))
.and_raise(error)
expect { cache.save([]) }.not_to raise_error
expect($stderr.string).to eq(<<~WARN)
Couldn't create cache directory. Continuing without cache.
Expand Down

0 comments on commit 708eb90

Please sign in to comment.