allow_any_instance_of with block followed by expect_any_instance_of without block leads to doubled unshifting of the original object
Created by: contentfree
Your environment
- Ruby version: 2.5.x
- rspec-mocks version: 3.10
Steps to reproduce
In a before block I have:
before(:each) do
allow_any_instance_of(MyClass).to receive(:my_method) { |instance, arg1, arg2|
debugger
true # whatever
}
end
then in a spec I have:
expect_any_instance_of(MyClass).to receive(:my_method).with(1,2)
Expected behavior
My expectation is that the allowed implementation would be called
Actual behavior
The allowed implementation is called, but it recurses once and ends of with the orig_object being passed to both instance
and arg1
. This, understandably leads to problems.
Partial Stacktrace
block (3 levels) in <top (required)> [my_class_spec.rb:18]
call [message_expectation.rb:694] (RSpec::Mocks::Implementation)
call [message_expectation.rb:693] (RSpec::Mocks::Implementation)
invoke_incrementing_actual_calls_by [message_expectation.rb:572] (RSpec::Mocks::MessageExpectation::ImplementationDetails)
invoke [message_expectation.rb:427] (RSpec::Mocks::MessageExpectation::ImplementationDetails)
invoke_incrementing_actual_calls_by [message_expectation.rb:574] (RSpec::Mocks::MessageExpectation::ImplementationDetails)
invoke [message_expectation.rb:427] (RSpec::Mocks::MessageExpectation::ImplementationDetails)
message_received [proxy.rb:217] (RSpec::Mocks::Proxy)
message_received [proxy.rb:361] (RSpec::Mocks::PartialDoubleProxy)
proxy_method_invoked [method_double.rb:78] (RSpec::Mocks::MethodDouble)
download [method_double.rb:64] (RSpec::Mocks::MethodDouble)
download [recorder.rb:262] (RSpec::Mocks::AnyInstance::Recorder)
download_results [my_class.rb:40] (MyClass)
... rest of the stack
You can see where it jumps into invoke
twice.