Permalink
Browse files

Fix bug where #excluding could not accept multiple keys

  • Loading branch information...
1 parent a7ede1a commit 01893fbcaaf3cde59cac4e771dea7e05b6dfa7f8 @alindeman alindeman committed Aug 15, 2011
Showing with 12 additions and 2 deletions.
  1. +2 −2 lib/json_spec/matchers.rb
  2. +10 −0 spec/json_spec/matchers_spec.rb
@@ -17,7 +17,7 @@
end
chain :excluding do |*keys|
- excluded_keys.add(*keys.map{|k| k.to_s })
+ excluded_keys.merge(keys.map{|k| k.to_s })
end
chain :including do |*keys|
@@ -60,7 +60,7 @@ def scrub(json, path = nil)
end
chain :excluding do |*keys|
- excluded_keys.add(*keys.map{|k| k.to_s })
+ excluded_keys.merge(*keys.map{|k| k.to_s })
end
chain :including do |*keys|
@@ -67,6 +67,11 @@
%({"id":1,"json":"spec"}).should be_json_eql(%({"id":2,"json":"spec"})).excluding(:id)
end
+ it "excludes multiple keys" do
+ JsonSpec.excluded_keys = []
+ %({"id":1,"json":"spec"}).should be_json_eql(%({"id":2,"json":"different"})).excluding(:id, :json)
+ end
+
it "includes globally-excluded hash keys per matcher" do
JsonSpec.excluded_keys = %w(id ignore)
%({"id":1,"json":"spec","ignore":"please"}).should_not be_json_eql(%({"id":2,"json":"spec","ignore":"this"})).including("id")
@@ -76,6 +81,11 @@
JsonSpec.excluded_keys = %w(id)
%({"id":1,"json":"spec"}).should_not be_json_eql(%({"id":2,"json":"spec"})).including(:id)
end
+
+ it "includes multiple keys" do
+ JsonSpec.excluded_keys = %w(id json)
+ %({"id":1,"json":"spec"}).should_not be_json_eql(%({"id":2,"json":"different"})).including(:id, :json)
+ end
end
context "include_json" do

0 comments on commit 01893fb

Please sign in to comment.