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

Add MessageExpectation cop #169

Merged
merged 2 commits into from
Aug 8, 2016
Merged

Add MessageExpectation cop #169

merged 2 commits into from
Aug 8, 2016

Conversation

backus
Copy link
Collaborator

@backus backus commented Aug 8, 2016

Enforces preferred styles of either

expect(foo).to receive(:bar)

or

allow(foo).to receive(:bar)

Fixes #23

backus added 2 commits August 8, 2016 02:51
Enforces preferred styles of either

  expect(foo).to receive(:bar)

or

  allow(foo).to receive(:bar)

Fixes #23
@backus backus mentioned this pull request Aug 8, 2016
@backus backus merged commit f757f4d into master Aug 8, 2016
@backus backus deleted the feature/MessageExpectation branch August 8, 2016 06:58
@andyw8
Copy link
Collaborator

andyw8 commented Aug 8, 2016

I'm not sure about this practicality of this one. Won't the vast majority of specs in any project need to use expect?

See https://relishapp.com/rspec/rspec-mocks/docs/basics/spies for some examples of the situations I had in mind for #23.

@backus
Copy link
Collaborator Author

backus commented Aug 8, 2016

@andyw8 I've run this on two projects now and it actually seems very effective. Basically this should be one piece of the puzzle in enforcing one of these two styles:

allow(foo).to receive(:bar)

# exercise system under test

expect(foo).to have_received(:bar)
expect(foo).to receive(:bar)

# exercise system under test

Note that this cop will never flag have_received. It simply says either "add spies before exercising your code" or "add a message expectation before exercising your code."

The second piece of the puzzle (which I haven't implemented yet) would be to find tests where spies are setup but not verified within that test. Basically it could detect (and autocorrect) the following:

allow(foo).to receive(:bar)
^^^^^^^^^^ Message expectation specified but not verified

thing.do_something(foo)

which could be autocorrected to

allow(foo).to receive(:bar)

thing.do_something(foo)

expect(foo).to have_received(:bar)

bquorning added a commit that referenced this pull request Oct 18, 2016
Instead of checking whether you create a stub or a mock, it now checks whether
you set message expectations using `receive` or `have_received`.

This relates to various issues:

 - #23
 - #169
 - #218
@bquorning bquorning mentioned this pull request Oct 18, 2016
4 tasks
bquorning added a commit that referenced this pull request Oct 18, 2016
Instead of checking whether you create a stub or a mock, it now checks whether
you set message expectations using `receive` or `have_received`.

This relates to various issues:

 - #23
 - #169
 - #218
bquorning added a commit that referenced this pull request Oct 19, 2016
Instead of checking whether you create a stub or a mock, it now checks whether
you set message expectations using `receive` or `have_received`.

This relates to various issues:

 - #23
 - #169
 - #218
bquorning added a commit that referenced this pull request Oct 19, 2016
Instead of checking whether you create a stub or a mock, it now checks whether
you set message expectations using `receive` or `have_received`.

This relates to various issues:

 - #23
 - #169
 - #218
bquorning added a commit that referenced this pull request Oct 27, 2016
Check that message expectations are set using spies.

This relates to various issues:

 - #23
 - #169
 - #218
 - #229
bquorning added a commit that referenced this pull request Oct 27, 2016
Users have expressed confusion over this cop; see

 - #23
 - #169
 - #218
 - #224
 - #229
bquorning added a commit that referenced this pull request Oct 27, 2016
Users have expressed confusion over this cop; see

 - #23
 - #169
 - #218
 - #224
 - #229
bquorning added a commit that referenced this pull request Oct 27, 2016
Check that message expectations are set using spies.

This relates to various issues:

 - #23
 - #169
 - #218
 - #229
bquorning added a commit that referenced this pull request Oct 27, 2016
Check that message expectations are set using spies.

This relates to various issues:

 - #23
 - #169
 - #218
 - #229
bquorning added a commit that referenced this pull request Nov 6, 2016
Check that message expectations are set using spies.

This relates to various issues:

 - #23
 - #169
 - #218
 - #229
andyw8 pushed a commit to andyw8/rubocop-rspec that referenced this pull request Dec 17, 2016
Users have expressed confusion over this cop; see

 - rubocop#23
 - rubocop#169
 - rubocop#218
 - rubocop#224
 - rubocop#229
andyw8 pushed a commit to andyw8/rubocop-rspec that referenced this pull request Dec 17, 2016
Check that message expectations are set using spies.

This relates to various issues:

 - rubocop#23
 - rubocop#169
 - rubocop#218
 - rubocop#229
markburns pushed a commit to markburns/rubocop-rails-ddd that referenced this pull request Nov 7, 2017
markburns pushed a commit to markburns/rubocop-rails-ddd that referenced this pull request Nov 7, 2017
Users have expressed confusion over this cop; see

 - rubocop#23
 - rubocop#169
 - rubocop#218
 - rubocop#224
 - rubocop#229
markburns pushed a commit to markburns/rubocop-rails-ddd that referenced this pull request Nov 7, 2017
Check that message expectations are set using spies.

This relates to various issues:

 - rubocop#23
 - rubocop#169
 - rubocop#218
 - rubocop#229
pirj pushed a commit to rubocop/rubocop-capybara that referenced this pull request Dec 29, 2022
pirj pushed a commit to rubocop/rubocop-capybara that referenced this pull request Dec 29, 2022
Check that message expectations are set using spies.

This relates to various issues:

 - rubocop/rubocop-rspec#23
 - rubocop/rubocop-rspec#169
 - rubocop/rubocop-rspec#218
 - rubocop/rubocop-rspec#229
ydah pushed a commit to rubocop/rubocop-factory_bot that referenced this pull request Apr 13, 2023
ydah pushed a commit to rubocop/rubocop-factory_bot that referenced this pull request Apr 13, 2023
Check that message expectations are set using spies.

This relates to various issues:

 - rubocop/rubocop-rspec#23
 - rubocop/rubocop-rspec#169
 - rubocop/rubocop-rspec#218
 - rubocop/rubocop-rspec#229
ydah pushed a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
ydah pushed a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
Check that message expectations are set using spies.

This relates to various issues:

 - rubocop/rubocop-rspec#23
 - rubocop/rubocop-rspec#169
 - rubocop/rubocop-rspec#218
 - rubocop/rubocop-rspec#229
ydah pushed a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
ydah pushed a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
Check that message expectations are set using spies.

This relates to various issues:

 - rubocop/rubocop-rspec#23
 - rubocop/rubocop-rspec#169
 - rubocop/rubocop-rspec#218
 - rubocop/rubocop-rspec#229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants