Message expectations on any_instance fails if any method is stubbed on an instance before it on 3.0
Created by: yujinakayama
This is a strange bug and I took some time to find out this minimal reproducible example:
describe 'message expectations on any_instance' do
context 'when non-related method is stubbed on a non-related instance BEFORE it' do
it 'should pass but fails' do
allow('non-related object').to receive(:non_related_method)
expect_any_instance_of(Object).to receive(:foo)
'something'.foo
end
end
context 'when non-related method is stubbed on a non-related instance AFTER it' do
it 'properly passes' do
expect_any_instance_of(Object).to receive(:foo)
allow('non-related obj').to receive(:non_related_method)
'something'.foo
end
end
context 'when non-related method is stubbed on any_instance BEFORE it' do
it 'properly passes' do
allow_any_instance_of(Object).to receive(:non_related_method)
expect_any_instance_of(Object).to receive(:foo)
'something'.foo
end
end
context 'when non-related method is stubbed on any_instance AFTER it' do
it 'properly passes' do
expect_any_instance_of(Object).to receive(:foo)
allow_any_instance_of(Object).to receive(:non_related_method)
'something'.foo
end
end
end
This fails on 3.0, but was working on 2.14 and 2.99.