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

Cop idea: Don’t stub when you’re mocking #221

Closed
bquorning opened this issue Oct 9, 2016 · 0 comments · Fixed by #226
Closed

Cop idea: Don’t stub when you’re mocking #221

bquorning opened this issue Oct 9, 2016 · 0 comments · Fixed by #226
Labels

Comments

@bquorning
Copy link
Collaborator

Sometimes, I see people defining a mock and tacking a stub onto the end it:

expect(foo).to receive(:bar).with(42).and_return("hello world")

subject.exercise

Now RSpec will expect foo to receive :bar with the argument 42.

If you read the code aloud, it very much sounds like "hello world" should also be part of the expectation. It isn’t.

I can think of at least two ways to rewrite this:

allow(foo).to receive(:bar).with(42).and_return("hello world")
expect(foo).to receive(:bar).with(42)

subject.exercise

or

allow(foo).to receive(:bar).with(42).and_return("hello world")

subject.exercise

expect(foo).to have_received(:bar).with(42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants