Previously the only requirement we put on Hash-like arguments was that they respond to #keys & #[] methods. However, the change in that commit we introduced an implicit assumption that they also respond to a #length method which is caused the problem described here.
However, ActionController::Parameters is commonly used in Rails apps and it does not respond to #length. So it seems better to add a guard condition to ensure the object responds to #keys and use that to determine the length.
Note that the HasEntry, HasKey and HasKeys matchers already work this way and so this feels like it makes HasEntries more consistent.
This was broken in this previous commit which was part of https://github.com/freerange/mocha/pull/660 and which was released in v2.4.3.
Previously the only requirement we put on
Hash
-like arguments was that they respond to#keys
&#[]
methods. However, the change in that commit we introduced an implicit assumption that they also respond to a#length
method which is caused the problem described here.However,
ActionController::Parameters
is commonly used in Rails apps and it does not respond to#length
. So it seems better to add a guard condition to ensure the object responds to#keys
and use that to determine the length.Note that the
HasEntry
,HasKey
andHasKeys
matchers already work this way and so this feels like it makesHasEntries
more consistent.