Skip to content

Fix problem with 'receive' on MRI 1.8.7 (when used on singleton methods in superclass and subclass)

gitlab-qa-bot requested to merge github/fork/alexdowad/more_receive_specs into master

Created by: alexdowad

The following code is broken on MRI 1.8.7:

class A; def self.foo; "foo"; end end
class B < A; end

allow(A).to receive(:foo) { ... }
allow(B).to receive(:foo) { ... }

The problem is that Proxy#original_method_handle_for gets the UnboundMethod which is stashed in the superclass' proxy, and tries to rebind it to the subclass. This doesn't work in 1.8.7.

Can you suggest a cleaner way to implement the workaround?

Merge request reports