Skip to content
Permalink
Browse files

Simplify spec for FormatterSet

This line:

    expect(formatter_set).to all(have_received(:started).with(files))

previously was

    expect(formatter_set).to all(receive(:started).with(files))

but was triggering a RSpec/SubjectStub offence, and there was a special
case treatment introduced to `rubocop-rspec` to relax detection of
stubbing when `all` matcher is used together with a message expectation
matcher.

The cop is not at the moment able to detect `have_received` matcher, but
there is an open pull request to improve the detection.

That pull request (rubocop-hq/rubocop-rspec#770)
is also aiming to remove that special case treatment, because, as
experiment has shown, across
[`real-world-ruby-apps`](https://github.com/jeromedalbert/real-world-ruby-apps)
and
[`real-world-rails`](https://github.com/eliotsykes/real-world-rails),
there is no other offences detected apart from this `FormatterSet` spec.

In any case, the rest of the spec don't use `all`, and are explicit of
which object the expectation is made against (by using `[0]`, `[1]`).

Also, using spies is not justified in this case.

It doesn't make much sense to use a `before` hook that is only run along
with a single example.
  • Loading branch information...
pirj authored and bbatsov committed May 21, 2019
1 parent 4061660 commit a0aaa233c20e18784d841212e1caa724bcc919f7
Showing with 5 additions and 12 deletions.
  1. +5 −12 spec/rubocop/formatter/formatter_set_spec.rb
@@ -10,21 +10,14 @@
end

describe 'formatter API method' do
before do
formatter_set.add_formatter('simple')
formatter_set.add_formatter('emacs')

formatter_set.each do |formatter|
allow(formatter).to receive(:started)
end
end

let(:files) { ['/path/to/file1', '/path/to/file2'] }

it 'invokes same method of all containing formatters' do
it 'invokes the same method of all containing formatters' do
formatter_set.add_formatter('simple')
formatter_set.add_formatter('emacs')
expect(formatter_set[0]).to receive(:started).with(files)
expect(formatter_set[1]).to receive(:started).with(files)
formatter_set.started(files)

expect(formatter_set).to all(have_received(:started).with(files))
end
end

0 comments on commit a0aaa23

Please sign in to comment.
You can’t perform that action at this time.