Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit fa5b1e8

Browse files
committed
Embrace 2.3+ workarounds
1 parent 6e0354e commit fa5b1e8

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/rspec/mocks/any_instance/recorder.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,17 @@ def restore_original_method!(method_name)
200200
remove_method method_name
201201

202202
# A @klass can have methods implemented (see Method#owner) in @klass
203-
# or inherited from a superclass. In ruby 2.2 and earlier, we can copy
204-
# a method regardless of the 'owner' and restore it to @klass after
205-
# because a call to 'super' from @klass's copied method would end up
206-
# calling the original class's superclass's method.
203+
# or inherited from a superclass.
207204
#
208-
# With the commit below, available starting in 2.3.0, ruby changed
209-
# this behavior and a call to 'super' from the method copied to @klass
205+
# A call to 'super' from the method copied to @klass
210206
# will call @klass's superclass method, which is the original
211207
# implementer of this method! This leads to very strange errors
212208
# if @klass's copied method calls 'super', since it would end up
213209
# calling itself, the original method implemented in @klass's
214210
# superclass.
215211
#
216-
# For ruby 2.3 and above, we need to only restore methods that
217-
# @klass originally owned.
218-
#
219-
# https://github.com/ruby/ruby/commit/c8854d2ca4be9ee6946e6d17b0e17d9ef130ee81
220-
if RUBY_VERSION < "2.3" || backed_up_method_owner[method_name.to_sym] == self
212+
# We need to only restore methods that @klass originally owned.
213+
if backed_up_method_owner[method_name.to_sym] == self
221214
alias_method method_name, alias_method_name
222215
end
223216
remove_method alias_method_name

0 commit comments

Comments
 (0)