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

wants to merge 1 commit into


None yet

2 participants


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.

@myronmarston myronmarston commented on the diff Aug 26, 2012
@@ -845,6 +845,26 @@ class RSpec::SampleRspecTestClass;end raise_error(RSpec::Mocks::MockExpectationError, "The message 'existing_method' was received by #{instance_two.inspect} but has already been received by #{instance_one.inspect}")
+ context "when a class overrides Object#method" do
+ before do
+ klass.class_eval <<-EOM
+ def method
+ "this is not awesome but does happen in real code"
+ end
+ end
myronmarston Aug 26, 2012 Member

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) {, :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).

alindeman Aug 26, 2012 Contributor

👍 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