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

Warn when allowances/expectations are set on any instance recorders. #433

Merged
merged 2 commits into from
Oct 16, 2013

Conversation

fables-tales
Copy link
Member

Closes #375

@fables-tales
Copy link
Member Author

@myronmarston please review this when you can :)

@xaviershay
Copy link
Member

Why don't we just raise an error instead?

@myronmarston
Copy link
Member

Why don't we just raise an error instead?

The point is to notify the user that that's almost certainly not what they want (which a warning is sufficient for), not to totally disallow mocking or stubbing a particular kind of object (which an error would do).

In #375 it was mentioned that rspec-mocks' own specs set mock expectations on the any instance recorder, so we'd have to change those, and it seems conceivable that an rspec extension gem could want to do the same thing.

if AnyInstance::Recorder === subject
RSpec.warning(
"`#{expression}(#{subject.klass}.any_instance).to` " <<
"is probably not what you meant, it does not stub on " <<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of stub here is confusing, as expect sets up a mock expectation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you be ok with "it does not allow" and "it does not expect" as then I can just use the "expression" variable, otherwise I'll add another argument that passes the correct language from the correct places.

@myronmarston
Copy link
Member

Looks good in general...nice work @samphippen :).

@xaviershay
Copy link
Member

So if it is what I want, I can't turn the warnings off.

Probably not worth worrying about. Hope it's obnoxious enough that people won't use it.

@JonRowe
Copy link
Member

JonRowe commented Oct 16, 2013

@xaviershay I worried about that briefly, but I think it's so edge case that it's fine. (It's only going to be us and/or 3rd party developers of extensions) in which case I think you just stub out RSpec.warning for that test.

@JonRowe
Copy link
Member

JonRowe commented Oct 16, 2013

LGTM to me too so merging.

JonRowe added a commit that referenced this pull request Oct 16, 2013
Warn when allowances/expectations are set on any instance recorders.
@JonRowe JonRowe merged commit 0180e72 into master Oct 16, 2013
@JonRowe JonRowe deleted the warn-allow-klass-any-instance branch October 16, 2013 04:07
@myronmarston
Copy link
Member

LGTM to me too so merging.

I did have a couple comments above that seem worth addressing...

@JonRowe
Copy link
Member

JonRowe commented Oct 16, 2013

Doh, somehow Github wasn't showing those in the thread but was showing "Looks good in general...nice work @samphippen :)."

@JonRowe
Copy link
Member

JonRowe commented Oct 16, 2013

I guess I should refresh tabs more often...

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.

Warn when using allow(Klass.any_instance)
4 participants