Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6 from alindeman/excluding_with_multiple_arguments

Fix bug where #excluding could not accept multiple keys
  • Loading branch information...
commit a65b1957f86bd1c8e8a9bd99e755cb72b2350fa0 2 parents a7ede1a + 01893fb
@bryckbost bryckbost authored
Showing with 12 additions and 2 deletions.
  1. +2 −2 lib/json_spec/matchers.rb
  2. +10 −0 spec/json_spec/matchers_spec.rb
View
4 lib/json_spec/matchers.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|
View
10 spec/json_spec/matchers_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.