Make include_json an identity function #61

Closed
wants to merge 3 commits into
from
@@ -15,7 +15,9 @@ def matches?(actual_json)
actual = parse_json(actual_json, @path)
expected = exclude_keys(parse_json(@expected_json))
case actual
- when Hash then actual.values.map{|v| exclude_keys(v) }.include?(expected)
+ when Hash then
+ expected.is_a?(Hash) && actual.select { |k,v| expected.include? k } == expected ||
+ actual.values.map{|v| exclude_keys(v) }.include?(expected)
when Array then actual.map{|e| exclude_keys(e) }.include?(expected)
when String then actual.include?(expected)
else false
@@ -45,6 +45,16 @@
json.should include_json(%([5,6]))
end
+ it "is an identity function" do
+ json = %({"one":1})
+ json.should include_json(%({"one":1}))
+ end
+
+ it "matches where expected is a subset of actual" do
+ json = %({"one":1, "two": 2})
+ json.should include_json(%({"one":1}))
+ end
+
it "matches a substring" do
json = %("json")
json.should include_json(%("js"))