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

Inconsistent behavior of SubjectStub #705

Closed
ixti opened this issue Oct 12, 2018 · 2 comments · Fixed by #770
Closed

Inconsistent behavior of SubjectStub #705

ixti opened this issue Oct 12, 2018 · 2 comments · Fixed by #770

Comments

@ixti
Copy link

ixti commented Oct 12, 2018

# fails
expect(subject).to receive(:my_method)
expect(subject).to receive(:my_method).and_call_original
expect(subject).to receive(:my_method).and_wrap_original { |m, *| m.call(42) }

# passes
expect(subject).not_to receive(:my_method)

It should either fail on not_to and to_no; or it should pass when matcher has and_call_original or and_wrap_original modifiers.

@ur5us
Copy link

ur5us commented Dec 14, 2018

Somewhat related: with the current implementation/error message it’s not clear to me why that would be a bad thing to begin with. When I stub a method on the subject it’s exactly what I want because I don’t care about testing #my_method itself, only that it gets called, e.g. composing a result.

@bquorning
Copy link
Collaborator

The problem of stubbing the object under test is described in “Smell 1: Stubject” of https://samphippen.com/introducing-rspec-smells/, and in this Thoughtbot blog post: https://robots.thoughtbot.com/don-t-stub-the-system-under-test

But yes, the cop‘s message is very vague.

@pirj pirj mentioned this issue May 15, 2019
5 tasks
kellysutton pushed a commit to kellysutton/rubocop-rspec that referenced this issue Oct 28, 2019
kellysutton pushed a commit to kellysutton/rubocop-rspec that referenced this issue Oct 28, 2019
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 a pull request may close this issue.

3 participants