Skip to content

Commit

Permalink
Reduce risk of hitting bug 12832 in Ruby v2.3
Browse files Browse the repository at this point in the history
Fixes #277.

This mirrors the change to `ClassMethod#hide_original_method` in
6f1c8b9.

This serves two purposes:

1. Make the implementation of `AnyInstanceMethod#hide_original_method`
closer to `ClassMethod#hide_original_method`.

2. Avoid the possibility of hitting Ruby bug 12832[1]. While I'm fairly
confident that calling `#instance_method` can trigger the bug in Ruby
I'm not convinced that it can be triggered by the code in
`AnyInstanceMethod#hide_original_method`. The bug appears to be
triggered when calling class methods and I'm not aware of a way to use
`any_instance_of` to stub class methods.

[1]: https://bugs.ruby-lang.org/issues/12832
  • Loading branch information
chrisroos committed Nov 3, 2016
1 parent 8f58edd commit eca7560
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mocha/any_instance_method.rb
Expand Up @@ -16,11 +16,11 @@ def reset_mocha
def hide_original_method
if @original_visibility = method_visibility(method)
begin
@original_method = stubbee.instance_method(method)
if RUBY_V2_PLUS
@definition_target = PrependedModule.new
stubbee.__send__ :prepend, @definition_target
else
@original_method = stubbee.instance_method(method)
if @original_method && @original_method.owner == stubbee
stubbee.send(:remove_method, method)
end
Expand Down

0 comments on commit eca7560

Please sign in to comment.