Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only restore an instance method on the owning class
Save the the original method owner before we back it up so we can only restore the method for the owning class. Fixes #1042 ```ruby class Shape def area(value) value end end class Circle < Shape def area super(2) end end class SmallCircle < Circle end ``` When using: allow_any_instance_of(SmallCircle).to receive(:area) Previously, we'd backup the area method from the first superclass that implements it. In this case, we'd copy Circle#area into SmallCircle with a backup name. Once this method is copied into SmallCircle, we lose the original ownership of Circle since SmallCircle now implements the method. At the end of the example, we remove the stubbing and rename the copied method back, causing SmallCircle to implement area when it never did previously. Any calls to SmallCircle#area would end up calling the contents of Circle#area, which calls super(2) on the Circle class, not Shape. Because Circle#area doesn't take any arguments, you get an ArgumentError. Previously, ruby 2.2 and below allowed this strange behavior to work, because it skipped calling the same method in super via this commit: ruby/ruby@c8854d2
- Loading branch information