Closed AntoineBecquet closed 1 year ago
Would you like to send a PR to fix this, @AntoineBecquet ?
Well, maybe if I have more time to investigate in the future, but for now I don't really know how these @chains_by_method_name
are managed.
Thanks for the reproduction, I've fixed this in #1501, I think its just a bad assumption that there'd always be an expectation, but for some reason there isn't, this isn't an invalid state for message chains because if you remove a stub it does end up as an empty list and this is the only method that doesnt handle that eventuality.
undefined method `expectation_fulfilled?' for nil:NilClass
When using
allow_any_instance_of
and/orexpect_any_instance_of
on two classes, one inheriting from the other, and having a failed expectation, this raise an errorundefined method 'expectation_fulfilled?' for nil:NilClass
.Your environment
Steps to reproduce
Expected behavior
Fails with the message :
Exactly one instance should have received the following message(s) but didn't: parent_method
Actual behavior
Raise an error :
Additional information
It's coming from theses lines : https://github.com/rspec/rspec-mocks/blob/main/lib/rspec/mocks/any_instance/message_chains.rb#L51-L52 In that case,
@chains_by_method_name
contains all expected or allowedmethod_name
in its keys, but one of thechains
value is an empty array.This seems related to https://github.com/rspec/rspec-rails/issues/1987, but related to rspec-mocks code-wise.