Open agrimm opened 8 years ago
Thanks for reporting this! This is definitely a bug but it's one that's not easily solved. I boiled it down into a failing spec in c7efa414e88c840fe4824cb011948cc1b3296d69 (just pushed into the expose-issue-1016
branch). Here's what's going on, using your reproduction repo as an example:
expect(decorated_user).to receive(:name).and_call_original
. This causes rspec-mocks to get the original method so that it can later call it.method_missing
to lazily define them on first use. That means that when that line runs, there is no original method for rspec-mocks to get. rspec-mocks handles method_missing
, though; in this case it generates a proc in place of the original method that, when called, will trigger method_missing
on the object, replicating the original behavior the object would have had (in theory, at least -- it falls over in this case).greeting
which internally calls name
. This is the method that rspec-mocks has defined on your object.method_missing
on the object.method_missing
implementation defines the method on the decorator class using delegate
from active support.method_missing
and the process repeats itself.The basic problem is that and_call_original
, as currently implemented, is not able to work with objects that implement the method lazily in method_missing
and then call it. I've tried a few things but haven't been able to come up with a fix yet.
Anyone is working on this one?
Not that I know of.
Sent from my iPhone
On Jun 8, 2018, at 2:39 AM, Thanh Le notifications@github.com wrote:
Anyone is working on this one?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
@thanhlelgg I'm not working on it.
Given the following the RSpec,
I get the following results
It seems that making the decorated object the target of the spec avoided the SystemStackError.
Also, once the code is exercised a bit, it seems to work ok. The third test is the same as the first, but it passes (the specs are order dependent in this case).
I've created an example app to replicate this issue. https://github.com/agrimm/rpsec_stack_replication
This involved RSpec 3.3.2, and Draper 2.1.0.
I tried searching for bugs involving SystemStackError, but they seemed to involve
any_instance_of
, unlike this bug.Apologies if I'm reporting this on the wrong sub-gem - I assume it's a mocking issue.