Hash matchers do not work as expected with descendants of `Hash`
Created by: agrberg
Currently using either hash_including
or hash_excluding
with an argument whose class inherits from Hash
has unexpected behavior. While this can be most easily discovered with Rails's ActiveSupport::HashWithIndifferentAccess
, it effects all descendants of Hash
.
hash_including({foo: 1}) === {foo: 1} #=> true
hash_including({foo: 1}.with_indifferent_access) === {foo: 1} #=> false
This is because ArgumentMatchers.anythingize_lonely_keys
looks exclusively for hashes and treats a Hash
descendant objects as key for an anything matcher.
hash_including({foo: 1}) #=> #<...HashIncludingMatcher @expected={:foo=>1}>
# vs
hash_including({foo: 1}.with_indifferent_access) #=> #<...HashIncludingMatcher @expected={{"foo"=>1}=>#<...AnyArgMatcher>}>
Pull request open at #1167