Skip to content
Browse files

accept symbols as field names

  • Loading branch information...
1 parent b95b570 commit ec8367388f23ea8fd2cc66ba8649603dd7a99a75 @AlexanderPavlenko committed with AlexanderPavlenko Oct 24, 2012
Showing with 3 additions and 1 deletion.
  1. +1 −1 lib/json_spec/matchers/have_json_fields.rb
  2. +2 −0 spec/json_spec/matchers/have_json_fields_spec.rb
View
2 lib/json_spec/matchers/have_json_fields.rb
@@ -11,7 +11,7 @@ def initialize(fields)
def matches?(json)
@data = parse_json(json, @path)
return false unless @data.is_a?(Hash)
- !@fields.map{|f| @data.has_key?(f)}.include?(false)
+ !@fields.map{|f| @data.has_key?(f.to_s)}.include?(false)
end
def at_path(path)
View
2 spec/json_spec/matchers/have_json_fields_spec.rb
@@ -9,9 +9,11 @@
it "fails for non-complete set of fields" do
%({"a": "a", "b": "b"}).should_not have_json_fields(%w(a b c))
+ %({"a": "a", "b": "b"}).should_not have_json_fields([:a, :b, :c])
end
it "matches complete set of fields" do
%({"a": "a", "b": "b", "c": "c"}).should have_json_fields(%w(a b c))
+ %({"a": "a", "b": "b", "c": "c"}).should have_json_fields([:a, :b, :c])
end
end

0 comments on commit ec83673

Please sign in to comment.
Something went wrong with that request. Please try again.