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

Switch to `receive` message expectation syntax #7067

Merged
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

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 committed May 21, 2019
commit 824213c4cb031bcb0ba0524c378251e5a0589c22
@@ -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

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.