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

any_instance is supported when a class overrides Object#method #181

Closed
wants to merge 1 commit into from

Conversation

alindeman
Copy link
Contributor

@myronmarston
Copy link
Member

Looks great. FWIW, I have a class in VCR that defines an argument-less method (i.e. VCR::Request#method which returns :get, :post, :put, :delete, etc), but at one point I realized that it would cause problems with meta-tools like rspec-mocks and I changed it to use a similar technique to what you've done here so that when called with an argument, it delegates to Object#method. It might be worth opening a PR with ActiveMerchant to have it do the same so that it can work better with other tools.

"this is not awesome but does happen in real code"
end
EOM
end
Copy link
Member

Choose a reason for hiding this comment

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

One suggestion -- this doesn't really communicate much about a real situation where #method would be overriden. Instead, you might consider doing something like:

let(:http_request_class) { Struct.new(:method, :uri) }

This communicates better (I think an HTTP request object is the main time you'd see method overriden since it's a proper term in that domain), is less code, and is a bit less "meta" (e.g. no class_eval).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I like it. I'll change, squash and merge.

@alindeman alindeman closed this in 645b158 Aug 26, 2012
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.

Recent any_instance Change Regarding Superclasses Causes Spec Failure
2 participants