def include(*expected)
Matcher.new :include, *expected do |*_expected|
diffable
match_for_should do |actual|
perform_match(:all?, :all?, actual, _expected)
end
match_for_should_not do |actual|
perform_match(:none?, :any?, actual, _expected)
end
def perform_match(predicate, hash_predicate, actual, _expected)
_expected.send(predicate) do |expected|
if comparing_hash_values?(actual, expected)
expected.send(hash_predicate) {|k,v| actual[k] == v}
elsif comparing_hash_keys?(actual, expected)
actual.has_key?(expected)
else
actual.include?(expected)
end
end
end
def comparing_hash_keys?(actual, expected)
actual.is_a?(Hash) && !expected.is_a?(Hash)
end
def comparing_hash_values?(actual, expected)
actual.is_a?(Hash) && expected.is_a?(Hash)
end
end
end