allow_any_instance_of(SomeModule) with and_wrap_original causes SystemStackError
Created by: Resonious
Subject of the issue
When using and_wrap_original
on allow_any_instance_of(SomeModule)
, calling the original method results in a SystemStackError
. It appears that the method passed by and_wrap_original
is actually the stubbed method, and so it's calling itself.
Your environment
- Ruby version:
2.6.2
- rspec-mocks version: reproduced on
3.9.0.pre 2aab10d
and3.8.0
Steps to reproduce
module MyModule
def do_work(arg)
@value += (arg * 2).to_s
end
end
class MyObject
include MyModule
def initialize
@value = ""
end
end
RSpec.describe MyObject do
specify "and_wrap_original works" do
allow_any_instance_of(MyModule).to receive(:do_work).and_wrap_original { |original, arg|
original.call(arg)
}
MyObject.new.do_work("a")
end
end
Expected behavior
The stub block calls the stubbed method.
Actual behavior
The stub block calls itself, resulting in SystemStackError
.