Skip to content

Commit

Permalink
support arbitrary json keys
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderPavlenko committed Feb 14, 2013
1 parent cfa57d0 commit 666c10e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 7 additions & 5 deletions features/keys.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ Feature: Paths
"z" : {
"d": 4,
"e": 5
}
},
"strange keys: '\_(\")_/', FTW!": true
}
"""

Scenario: Base paths
When I get the JSON
Then the JSON should have keys "a, b, c"
Then the JSON should not have keys "d, e"
Then the JSON at "z" should have keys "d, e"
Then the JSON at "z" should not have keys "m, z"
Then the JSON should have keys "a", "b", "c"
Then the JSON should not have keys "d", "e"
Then the JSON at "z" should have keys "d", "e"
Then the JSON at "z" should not have keys "m", "z"
Then the JSON should have keys "strange keys: '\_(\")_/', FTW!", "a", "b"

Scenario: Table format
When I get the JSON
Expand Down
5 changes: 3 additions & 2 deletions lib/json_spec/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@
end
end

Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? have keys "(.*)"$/ do |base, negative, keys|
match = have_json_keys(keys.split(',').map(&:strip))
Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? have keys (.*)$/ do |base, negative, keys|
keys = eval("[#{keys}]")
match = have_json_keys(keys)
match = match.at_path(base) if base
if negative
last_json.should_not match
Expand Down

0 comments on commit 666c10e

Please sign in to comment.