Skip to content

Commit

Permalink
Work around JRuby returning empty parameters on repeated calls.
Browse files Browse the repository at this point in the history
This fixes a JRuby bug where by repeated calls to parameters on unbound
instance methods falsely return []

e.g. on JRuby 1.7.4
```Ruby
  String.instance_method(:replace).parameters
  # => [[:req]]
  String.instance_method(:replace).parameters
  # => []
```

And with this "fix"

```Ruby
  String.dup.instance_method(:replace).parameters
  # => [[:req]]
  String.dup.instance_method(:replace).parameters
  # => [[:req]]
```
  • Loading branch information
JonRowe committed Oct 22, 2013
1 parent 4932f3c commit 4301700
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/rspec/mocks/method_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,17 @@ def method_implemented?(m)
# definition of "implemented". However, it's the best we can do.
alias method_defined? method_implemented?

def find_method(m)
m.instance_method(@method_name)
# works around the fact that repeated calls for method parameters will
# falsely return empty arrays on JRuby in certain circumstances, this
# is necessary here because we can't dup/clone UnboundMethods
if PLATFORM == 'java'
def find_method(m)
m.dup.instance_method(@method_name)
end
else
def find_method(m)
m.instance_method(@method_name)
end
end
end

Expand Down

0 comments on commit 4301700

Please sign in to comment.