Skip to content

Commit

Permalink
Receive: only avoid overriding own methods
Browse files Browse the repository at this point in the history
Fix: #1530

My understanding of this `next if method_defined?` check that there since
this class was added in 08ec2e8
is that it's to prevent accidentally overriding Matcher or own methods.

If my understanding is correct, then we should ignore methods inherited from
`Object`.
  • Loading branch information
byroot authored and JonRowe committed Mar 10, 2023
1 parent 6c55205 commit a2af97d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rspec/mocks/matchers/receive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def setup_any_instance_allowance(subject, &block)
setup_any_instance_method_substitute(subject, :stub, block)
end

own_methods = (instance_methods - superclass.instance_methods)
MessageExpectation.public_instance_methods(false).each do |method|
next if method_defined?(method)
next if own_methods.include?(method)

define_method(method) do |*args, &block|
@recorded_customizations << ExpectationCustomization.new(method, args, block)
Expand Down

2 comments on commit a2af97d

@mathieujobin
Copy link

Choose a reason for hiding this comment

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

has this been released?

@mathieujobin
Copy link

Choose a reason for hiding this comment

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

looks included in 3.12.4 thanks
image

Please sign in to comment.