json_spec 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -141,8 +141,8 @@ Now, you can use the json_spec steps in your features:
141
141
  """
142
142
 
143
143
  The background steps above aren't provided by json_spec and the "visit" steps are provided by
144
- Capybara. The remaining steps all stem from the five steps that json_spec provides. They're
145
- versatile and can be used in plenty of different formats:
144
+ Capybara. The remaining steps, json_spec provides. They're versatile and can be used in plenty of
145
+ different formats:
146
146
 
147
147
  Then the JSON should be:
148
148
  """
@@ -183,6 +183,30 @@ versatile and can be used in plenty of different formats:
183
183
 
184
184
  _All instances of "should" above could be followed by "not" and all instances of "JSON" could be downcased and/or followed by "response."_
185
185
 
186
+ ### Table format
187
+
188
+ Another step exists that uses Cucumber's table formatting and wraps two of the above steps:
189
+
190
+ Then the JSON should have the following:
191
+ | path/0 | {"key":"value"} |
192
+ | path/1 | ["entry","entry"] |
193
+
194
+ Any number of rows can be given. The step above is equivalent to:
195
+
196
+ Then the JSON at "path/0" should be {"key":"value"}
197
+ And the JSON at "path/1" should be ["entry","entry"]
198
+
199
+ If only one column is given:
200
+
201
+ Then the JSON should have the following:
202
+ | path/0 |
203
+ | path/1 |
204
+
205
+ This is equivalent to:
206
+
207
+ Then the JSON should have "path/0"
208
+ And the JSON should have "path/1"
209
+
186
210
  ### JSON Memory
187
211
 
188
212
  There's one more Cucumber step that json_spec provides which hasn't been used above. It's used to
@@ -231,3 +231,29 @@ Feature: Equivalence
231
231
  Then the JSON at "created_at" should be "2011-07-08 02:27:34"
232
232
  And the JSON at "id" should be 1
233
233
  And the JSON at "updated_at" should be "2011-07-08 02:28:50"
234
+
235
+ Scenario: Table format
236
+ When I get the JSON
237
+ Then the JSON should have the following:
238
+ | array | ["json","spec"] |
239
+ | array/0 | "json" |
240
+ | array/1 | "spec" |
241
+ | created_at | "2011-07-08 02:27:34" |
242
+ | empty_array | [] |
243
+ | empty_hash | {} |
244
+ | false | false |
245
+ | float | 10.0 |
246
+ | hash | {"json":"spec"} |
247
+ | hash/json | "spec" |
248
+ | id | 1 |
249
+ | integer | 10 |
250
+ | negative | -10 |
251
+ | null | null |
252
+ | string | "json_spec" |
253
+ | true | true |
254
+ | updated_at | "2011-07-08 02:28:50" |
255
+ And the JSON at "array" should have the following:
256
+ | 0 | "json" |
257
+ | 1 | "spec" |
258
+ And the JSON at "hash" should have the following:
259
+ | json | "spec" |
@@ -27,7 +27,20 @@ Feature: Paths
27
27
  }
28
28
  """
29
29
 
30
+ Scenario: Base paths
31
+ When I get the JSON
32
+ Then the JSON should have "array"
33
+ And the JSON should have "hash"
34
+ And the JSON should have "id"
35
+
30
36
  Scenario: Nested paths
37
+ When I get the JSON
38
+ Then the JSON should have "array/0"
39
+ And the JSON should have "array/1"
40
+ And the JSON should have "hash/even"
41
+ And the JSON should have "hash/odd"
42
+
43
+ Scenario: Deeply nested paths
31
44
  When I get the JSON
32
45
  Then the JSON should have "array/0/one"
33
46
  And the JSON should have "array/0/two"
@@ -41,3 +54,21 @@ Feature: Paths
41
54
  Scenario: Ignored paths
42
55
  When I get the JSON
43
56
  Then the JSON should have "id"
57
+
58
+ Scenario: Table format
59
+ When I get the JSON
60
+ Then the JSON should have the following:
61
+ | array |
62
+ | hash |
63
+ | array/0 |
64
+ | array/1 |
65
+ | hash/even |
66
+ | hash/odd |
67
+ | array/0/one |
68
+ | array/0/two |
69
+ | array/1/four |
70
+ | array/1/three |
71
+ | hash/even/0 |
72
+ | hash/even/1 |
73
+ | hash/odd/0 |
74
+ | hash/odd/1 |
@@ -26,6 +26,18 @@ Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? be (".*"|\-?
26
26
  end
27
27
  end
28
28
 
29
+ Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should have the following:$/ do |base, table|
30
+ table.rows.each do |path, value|
31
+ path = [base, path].compact.join("/")
32
+
33
+ if value
34
+ Then %(the JSON at "#{path}" should be:), value
35
+ else
36
+ Then %(the JSON should have "#{path}")
37
+ end
38
+ end
39
+ end
40
+
29
41
  Then /^the (?:JSON|json)(?: response)? should( not)? have "(.*)"$/ do |negative, path|
30
42
  if negative
31
43
  last_json.should_not have_json_path(path)
@@ -1,3 +1,3 @@
1
1
  module JsonSpec
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-09 00:00:00.000000000 -04:00
12
+ date: 2011-07-10 00:00:00.000000000 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
- requirement: &2155974100 !ruby/object:Gem::Requirement
17
+ requirement: &2156046080 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '1.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2155974100
25
+ version_requirements: *2156046080
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2155973600 !ruby/object:Gem::Requirement
28
+ requirement: &2156045580 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2155973600
36
+ version_requirements: *2156045580
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rake
39
- requirement: &2155973140 !ruby/object:Gem::Requirement
39
+ requirement: &2156045120 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0.9'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2155973140
47
+ version_requirements: *2156045120
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: cucumber
50
- requirement: &2155972680 !ruby/object:Gem::Requirement
50
+ requirement: &2156044660 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '1.0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2155972680
58
+ version_requirements: *2156044660
59
59
  description: Easily handle JSON in RSpec and Cucumber
60
60
  email:
61
61
  - steve.richert@gmail.com