You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
modulePrependerendclassFakeClassprependPrependerdeffake_method(arg)return{}endenddescribeFakeClassdocontext"When a test stubs the prepended class"doit"should not persist this stub"doallow_any_instance_of(FakeClass).toreceive(:fake_method).with("random argument").and_return("returned value")endendcontext"when the class is no longer stubbed"doit"should not be affected by other tests"doexpect(FakeClass.new.fake_method("non-random")).toeq({})endendend
The above test passes in MRI Ruby.
Actual Behavior
The allow_any_instance_of is not getting cleared in jruby causing the second test to fail
Failures:
1) FakeClass when the class is no longer stubbed should not be affected by other tests
Failure/Error: expect(FakeClass.new.fake_method("non-random")).to eq({})
#<FakeClass:0x74235045> received :fake_method with unexpected arguments
expected: ("random argument")
got: ("non-random")
Please stub a default value first if message might be received with other args as well.
# ./spec/rspec_scope_spec.rb:25:in `block in (root)'
Finished in 0.06384 seconds (files took 0.46047 seconds to load)
2 examples, 1 failure
It is important to note that this tests behaves as expected without a prepend Module statement.
Environment
I've created a sample project https://github.com/NC-phuh/jruby_rspec_bug that fully shows this issue.
Expected Behavior
Actual Behavior
allow_any_instance_of
is not getting cleared in jruby causing the second test to failIt is important to note that this tests behaves as expected without a prepend Module statement.
I've traced this bug to https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/any_instance/recorder.rb#L191
The line returns false even though both objects have the same id.
return unless @klass.instance_method(method_name).owner.to_s == @klass.to_s
The text was updated successfully, but these errors were encountered: