Sha256: 171bdf0bb2e9f7c5ce37f907d2e6d20b28afee69d8433055aa831e166e548a5b
Contents?: true
Size: 625 Bytes
Versions: 52
Compression:
Stored size: 625 Bytes
Contents
# checks if actual contains all the key-value pairs that expected does, # ignoring order for any child arrays RSpec::Matchers.define :contain_hash do |expected| match do |actual| contains_hash?(expected, actual) end end def contains_hash?(expected, actual) expected.all? do |key, value| unordered_match(actual[key], value) end end def unordered_match(expected, actual) case when [expected, actual].all?{|val| val.is_a? Array } expected.all?{|el| actual.include? el } when [expected, actual].all?{|val| val.is_a? Hash } contains_hash?(expected, actual) else expected == actual end end
Version data entries
52 entries across 52 versions & 1 rubygems