jsontest 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +20 -0
- data/README.md +343 -0
- data/Rakefile +18 -0
- data/features/equivalence.feature +286 -0
- data/features/files.feature +89 -0
- data/features/inclusion.feature +154 -0
- data/features/memory.feature +221 -0
- data/features/paths.feature +74 -0
- data/features/sizes.feature +38 -0
- data/features/step_definitions/steps.rb +7 -0
- data/features/support/env.rb +9 -0
- data/features/types.feature +24 -0
- data/gemfiles/rspec2.gemfile +10 -0
- data/gemfiles/rspec3.gemfile +10 -0
- data/jsontest.gemspec +22 -0
- data/lib/jsontest.rb +14 -0
- data/lib/jsontest/configuration.rb +30 -0
- data/lib/jsontest/cucumber.rb +95 -0
- data/lib/jsontest/errors.rb +46 -0
- data/lib/jsontest/exclusion.rb +26 -0
- data/lib/jsontest/helpers.rb +62 -0
- data/lib/jsontest/matchers.rb +33 -0
- data/lib/jsontest/matchers/be_json_eql.rb +66 -0
- data/lib/jsontest/matchers/have_json_path.rb +32 -0
- data/lib/jsontest/matchers/have_json_size.rb +39 -0
- data/lib/jsontest/matchers/have_json_type.rb +52 -0
- data/lib/jsontest/matchers/include_json.rb +63 -0
- data/lib/jsontest/memory.rb +19 -0
- data/lib/jsontest/messages.rb +8 -0
- data/spec/jsontest/configuration_spec.rb +62 -0
- data/spec/jsontest/helpers_spec.rb +111 -0
- data/spec/jsontest/matchers/be_json_eql_spec.rb +111 -0
- data/spec/jsontest/matchers/have_json_path_spec.rb +29 -0
- data/spec/jsontest/matchers/have_json_size_spec.rb +61 -0
- data/spec/jsontest/matchers/have_json_type_spec.rb +92 -0
- data/spec/jsontest/matchers/include_json_spec.rb +96 -0
- data/spec/jsontest/matchers_spec.rb +77 -0
- data/spec/jsontest/memory_spec.rb +32 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/files/one.json +1 -0
- data/spec/support/files/project/one.json +1 -0
- data/spec/support/files/project/two.json +18 -0
- data/spec/support/files/project/version/one.json +1 -0
- data/spec/support/files/project/version/two.json +3 -0
- data/spec/support/files/two.json +24 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 86fd405580154f153393a0b56f41fe40e9b924f0adff461d99a6b5750535e9dc
|
4
|
+
data.tar.gz: bca245249d098f4ed747715366a9cd0ea1b073b04b104e67af0fdcf404640594
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4679a1d08234e627f32f2a468c915e37fbd92efa0b7f9135d3c785d5c40aea0c7634304c10f2340bf6b28b266d5b9213818ac3bd8b07df79fccb6a871d7e8c1
|
7
|
+
data.tar.gz: 2658206af8504222888eb3993399622d159b760ed292ca6814872719718708e09e77d299d59b276810fa328f523e284b0e139a5f40daa7145dab13a35a1ff655
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
after_success:
|
2
|
+
- bundle exec codeclimate-test-reporter
|
3
|
+
branches:
|
4
|
+
only:
|
5
|
+
- master
|
6
|
+
gemfile:
|
7
|
+
- gemfiles/rspec2.gemfile
|
8
|
+
- gemfiles/rspec3.gemfile
|
9
|
+
language: ruby
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- rvm: ruby-head
|
13
|
+
- rvm: "2.0"
|
14
|
+
- rvm: "2.1"
|
15
|
+
rvm:
|
16
|
+
- "2.0"
|
17
|
+
- "2.1"
|
18
|
+
- "2.2.7"
|
19
|
+
- "2.3.4"
|
20
|
+
- "2.4.1"
|
21
|
+
- ruby-head
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
## Unreleased (master)
|
2
|
+
|
3
|
+
- Added Changelog
|
4
|
+
- Fix RSpec warnings for uninitialized instance variables on matchers [#78](https://github.com/collectiveidea/jsontest/pull/78)
|
5
|
+
|
6
|
+
## Version 1.1.4
|
7
|
+
|
8
|
+
- Raise error when checking a size of a json ruby value of nil [#82](https://github.com/collectiveidea/jsontest/pull/82)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright © 2018 Steve Richert, Michiel Boekhoff
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,343 @@
|
|
1
|
+
# jsontest
|
2
|
+
|
3
|
+
This is a fork of json_spec, including new features and fixes.
|
4
|
+
|
5
|
+
Easily handle JSON in RSpec and Cucumber
|
6
|
+
|
7
|
+
[](http://rubygems.org/gems/jsontest)
|
8
|
+
[](https://travis-ci.com/michielboekhoff/jsontest)
|
9
|
+
[](https://codeclimate.com/github/michielboekhoff/jsontest/maintainability)
|
10
|
+
[](https://codeclimate.com/github/michielboekhoff/jsontest/test_coverage)
|
11
|
+
|
12
|
+
## RSpec
|
13
|
+
|
14
|
+
jsontest defines five new RSpec matchers:
|
15
|
+
|
16
|
+
* `be_json_eql`
|
17
|
+
* `include_json`
|
18
|
+
* `have_json_path`
|
19
|
+
* `have_json_type`
|
20
|
+
* `have_json_size`
|
21
|
+
|
22
|
+
The new matchers could be used in RSpec as follows:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
describe User do
|
26
|
+
let(:user){ User.create!(first_name: "Steve", last_name: "Richert") }
|
27
|
+
|
28
|
+
context "#to_json" do
|
29
|
+
it "includes names" do
|
30
|
+
names = %({"first_name":"Steve","last_name":"Richert"})
|
31
|
+
user.to_json.should be_json_eql(names).excluding("friends")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "includes the ID" do
|
35
|
+
user.to_json.should have_json_path("id")
|
36
|
+
user.to_json.should have_json_type(Integer).at_path("id")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "includes friends" do
|
40
|
+
user.to_json.should have_json_size(0).at_path("friends")
|
41
|
+
|
42
|
+
friend = User.create!(first_name: "Catie", last_name: "Richert")
|
43
|
+
user.friends << friend
|
44
|
+
|
45
|
+
user.to_json.should have_json_size(1).at_path("friends")
|
46
|
+
user.to_json.should include_json(friend.to_json)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
jsontest also provides some useful helpers for RSpec tests:
|
53
|
+
|
54
|
+
* `parse_json`
|
55
|
+
* `normalize_json`
|
56
|
+
* `generate_normalized_json`
|
57
|
+
* `load_json`
|
58
|
+
|
59
|
+
To start using them add an include them in your RSpec configuration:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
RSpec.configure do |config|
|
63
|
+
config.include JsonTest::Helpers
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
You can find usage examples for the helpers in [`spec/jsontest/helpers_spec.rb`](https://github.com/collectiveidea/jsontest/blob/master/spec/jsontest/helpers_spec.rb)
|
68
|
+
|
69
|
+
### Exclusions
|
70
|
+
|
71
|
+
jsontest ignores certain hash keys by default when comparing JSON:
|
72
|
+
|
73
|
+
* `id`
|
74
|
+
* `created_at`
|
75
|
+
* `updated_at`
|
76
|
+
|
77
|
+
It's oftentimes helpful when evaluating JSON representations of newly-created ActiveRecord records
|
78
|
+
so that the new ID and timestamps don't have to be known. These exclusions are globally
|
79
|
+
customizeable:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
JsonTest.configure do
|
83
|
+
exclude_keys "created_at", "updated_at"
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
Now, the `id` key will be included in jsontest's comparisons. Keys can also be excluded/included
|
88
|
+
per matcher by chaining the `excluding` or `including` methods (as shown above) which will add or
|
89
|
+
subtract from the globally excluded keys, respectively.
|
90
|
+
|
91
|
+
### Paths
|
92
|
+
|
93
|
+
Each of jsontest's matchers deal with JSON "paths." These are simple strings of "/" separated
|
94
|
+
hash keys and array indexes. For instance, with the following JSON:
|
95
|
+
|
96
|
+
{
|
97
|
+
"first_name": "Steve",
|
98
|
+
"last_name": "Richert",
|
99
|
+
"friends": [
|
100
|
+
{
|
101
|
+
"first_name": "Catie",
|
102
|
+
"last_name": "Richert"
|
103
|
+
}
|
104
|
+
]
|
105
|
+
}
|
106
|
+
|
107
|
+
We could access the first friend's first name with the path `"friends/0/first_name"`.
|
108
|
+
|
109
|
+
## Cucumber
|
110
|
+
|
111
|
+
jsontest provides Cucumber steps that utilize its RSpec matchers and that's where jsontest really
|
112
|
+
shines. This is perfect for testing your app's JSON API.
|
113
|
+
|
114
|
+
In order to use the Cucumber steps, in your `env.rb` you must:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
require "jsontest/cucumber"
|
118
|
+
```
|
119
|
+
|
120
|
+
You also need to define a `last_json` method. If you're using Capybara, it could be as simple as:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
def last_json
|
124
|
+
page.source
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
Now, you can use the jsontest steps in your features:
|
129
|
+
|
130
|
+
```cucumber
|
131
|
+
Feature: User API
|
132
|
+
Background:
|
133
|
+
Given the following users exist:
|
134
|
+
| id | first_name | last_name |
|
135
|
+
| 1 | Steve | Richert |
|
136
|
+
| 2 | Catie | Richert |
|
137
|
+
And "Steve Richert" is friends with "Catie Richert"
|
138
|
+
|
139
|
+
Scenario: Index action
|
140
|
+
When I visit "/users.json"
|
141
|
+
Then the JSON response should have 2 users
|
142
|
+
And the JSON response at "0/id" should be 1
|
143
|
+
And the JSON response at "1/id" should be 2
|
144
|
+
|
145
|
+
Scenario: Show action
|
146
|
+
When I visit "/users/1.json"
|
147
|
+
Then the JSON response at "first_name" should be "Steve"
|
148
|
+
And the JSON response at "last_name" should be "Richert"
|
149
|
+
And the JSON response should have "created_at"
|
150
|
+
And the JSON response at "created_at" should be a string
|
151
|
+
And the JSON response at "friends" should be:
|
152
|
+
"""
|
153
|
+
[
|
154
|
+
{
|
155
|
+
"id": 2,
|
156
|
+
"first_name": "Catie",
|
157
|
+
"last_name": "Richert"
|
158
|
+
}
|
159
|
+
]
|
160
|
+
"""
|
161
|
+
```
|
162
|
+
|
163
|
+
The background steps above aren't provided by jsontest and the "visit" steps are provided by
|
164
|
+
Capybara. The remaining steps, jsontest provides. They're versatile and can be used in plenty of
|
165
|
+
different formats:
|
166
|
+
|
167
|
+
```cucumber
|
168
|
+
Then the JSON should be:
|
169
|
+
"""
|
170
|
+
{
|
171
|
+
"key": "value"
|
172
|
+
}
|
173
|
+
"""
|
174
|
+
Then the JSON at "path" should be:
|
175
|
+
"""
|
176
|
+
[
|
177
|
+
"entry",
|
178
|
+
"entry"
|
179
|
+
]
|
180
|
+
"""
|
181
|
+
|
182
|
+
Then the JSON should be {"key":"value"}
|
183
|
+
Then the JSON at "path" should be {"key":"value"}
|
184
|
+
Then the JSON should be ["entry","entry"]
|
185
|
+
Then the JSON at "path" should be ["entry","entry"]
|
186
|
+
Then the JSON at "path" should be "string"
|
187
|
+
Then the JSON at "path" should be 10
|
188
|
+
Then the JSON at "path" should be 10.0
|
189
|
+
Then the JSON at "path" should be 1e+1
|
190
|
+
Then the JSON at "path" should be true
|
191
|
+
Then the JSON at "path" should be false
|
192
|
+
Then the JSON at "path" should be null
|
193
|
+
|
194
|
+
Then the JSON should include:
|
195
|
+
"""
|
196
|
+
{
|
197
|
+
"key": "value"
|
198
|
+
}
|
199
|
+
"""
|
200
|
+
Then the JSON at "path" should include:
|
201
|
+
"""
|
202
|
+
[
|
203
|
+
"entry",
|
204
|
+
"entry"
|
205
|
+
]
|
206
|
+
"""
|
207
|
+
|
208
|
+
Then the JSON should include {"key":"value"}
|
209
|
+
Then the JSON at "path" should include {"key":"value"}
|
210
|
+
Then the JSON should include ["entry","entry"]
|
211
|
+
Then the JSON at "path" should include ["entry","entry"]
|
212
|
+
Then the JSON should include "string"
|
213
|
+
Then the JSON at "path" should include "string"
|
214
|
+
Then the JSON should include 10
|
215
|
+
Then the JSON at "path" should include 10
|
216
|
+
Then the JSON should include 10.0
|
217
|
+
Then the JSON at "path" should include 10.0
|
218
|
+
Then the JSON should include 1e+1
|
219
|
+
Then the JSON at "path" should include 1e+1
|
220
|
+
Then the JSON should include true
|
221
|
+
Then the JSON at "path" should include true
|
222
|
+
Then the JSON should include false
|
223
|
+
Then the JSON at "path" should include false
|
224
|
+
Then the JSON should include null
|
225
|
+
Then the JSON at "path" should include null
|
226
|
+
|
227
|
+
Then the JSON should have "path"
|
228
|
+
|
229
|
+
Then the JSON should be a hash
|
230
|
+
Then the JSON at "path" should be an array
|
231
|
+
Then the JSON at "path" should be a float
|
232
|
+
|
233
|
+
Then the JSON should have 1 entry
|
234
|
+
Then the JSON at "path" should have 2 entries
|
235
|
+
Then the JSON should have 3 keys
|
236
|
+
Then the JSON should have 4 whatevers
|
237
|
+
```
|
238
|
+
|
239
|
+
_All instances of "should" above could be followed by "not" and all instances of "JSON" could be downcased and/or followed by "response."_
|
240
|
+
|
241
|
+
### Table Format
|
242
|
+
|
243
|
+
Another step exists that uses Cucumber's table formatting and wraps two of the above steps:
|
244
|
+
|
245
|
+
```cucumber
|
246
|
+
Then the JSON should have the following:
|
247
|
+
| path/0 | {"key":"value"} |
|
248
|
+
| path/1 | ["entry","entry"] |
|
249
|
+
```
|
250
|
+
|
251
|
+
Any number of rows can be given. The step above is equivalent to:
|
252
|
+
|
253
|
+
```cucumber
|
254
|
+
Then the JSON at "path/0" should be {"key":"value"}
|
255
|
+
And the JSON at "path/1" should be ["entry","entry"]
|
256
|
+
```
|
257
|
+
|
258
|
+
If only one column is given:
|
259
|
+
|
260
|
+
```cucumber
|
261
|
+
Then the JSON should have the following:
|
262
|
+
| path/0 |
|
263
|
+
| path/1 |
|
264
|
+
```
|
265
|
+
|
266
|
+
This is equivalent to:
|
267
|
+
|
268
|
+
```cucumber
|
269
|
+
Then the JSON should have "path/0"
|
270
|
+
And the JSON should have "path/1"
|
271
|
+
```
|
272
|
+
|
273
|
+
### JSON Memory
|
274
|
+
|
275
|
+
There's one more Cucumber step that jsontest provides which hasn't been used above. It's used to
|
276
|
+
memorize JSON for reuse in later steps. You can "keep" all or a portion of the JSON by giving a
|
277
|
+
name by which to remember it.
|
278
|
+
|
279
|
+
```cucumber
|
280
|
+
Feature: User API
|
281
|
+
Scenario: Index action includes full user JSON
|
282
|
+
Given the following user exists:
|
283
|
+
| id | first_name | last_name |
|
284
|
+
| 1 | Steve | Richert |
|
285
|
+
And I visit "/users/1.json"
|
286
|
+
And I keep the JSON response as "USER_1"
|
287
|
+
When I visit "/users.json"
|
288
|
+
Then the JSON response should be:
|
289
|
+
"""
|
290
|
+
[
|
291
|
+
%{USER_1}
|
292
|
+
]
|
293
|
+
"""
|
294
|
+
```
|
295
|
+
|
296
|
+
You can memorize JSON at a path:
|
297
|
+
|
298
|
+
```cucumber
|
299
|
+
Given I keep the JSON response at "first_name" as "FIRST_NAME"
|
300
|
+
```
|
301
|
+
|
302
|
+
You can remember JSON at a path:
|
303
|
+
|
304
|
+
```cucumber
|
305
|
+
Then the JSON response at "0/first_name" should be:
|
306
|
+
"""
|
307
|
+
%{FIRST_NAME}
|
308
|
+
"""
|
309
|
+
```
|
310
|
+
|
311
|
+
You can also remember JSON inline:
|
312
|
+
|
313
|
+
```cucumber
|
314
|
+
Then the JSON response at "0/first_name" should be %{FIRST_NAME}
|
315
|
+
```
|
316
|
+
|
317
|
+
### More
|
318
|
+
|
319
|
+
Check out the [specs](https://github.com/collectiveidea/jsontest/blob/master/spec)
|
320
|
+
and [features](https://github.com/collectiveidea/jsontest/blob/master/features) to see all the
|
321
|
+
various ways you can use jsontest.
|
322
|
+
|
323
|
+
## Contributing
|
324
|
+
|
325
|
+
If you come across any issues, please [tell us](https://github.com/collectiveidea/jsontest/issues).
|
326
|
+
Pull requests (with tests) are appreciated. No pull request is too small. Please help with:
|
327
|
+
|
328
|
+
* Reporting bugs
|
329
|
+
* Suggesting features
|
330
|
+
* Writing or improving documentation
|
331
|
+
* Fixing typos
|
332
|
+
* Cleaning whitespace
|
333
|
+
* Refactoring code
|
334
|
+
* Adding tests
|
335
|
+
* Closing [issues](https://github.com/collectiveidea/jsontest/issues)
|
336
|
+
|
337
|
+
If you report a bug and don't include a fix, please include a failing test.
|
338
|
+
|
339
|
+
## Copyright
|
340
|
+
|
341
|
+
Copyright © 2011 Steve Richert
|
342
|
+
|
343
|
+
See [LICENSE](https://github.com/collectiveidea/jsontest/blob/master/LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "cucumber/rake/task"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
6
|
+
task.rspec_opts = "--warnings"
|
7
|
+
end
|
8
|
+
|
9
|
+
Cucumber::Rake::Task.new(:cucumber) do |task|
|
10
|
+
task.cucumber_opts = "--tags ~@fail"
|
11
|
+
end
|
12
|
+
|
13
|
+
Cucumber::Rake::Task.new(:negative_cucumber) do |task|
|
14
|
+
task.cucumber_opts = "--tags @fail --wip"
|
15
|
+
end
|
16
|
+
|
17
|
+
task test: [:spec, :cucumber, :negative_cucumber]
|
18
|
+
task default: :test
|
@@ -0,0 +1,286 @@
|
|
1
|
+
Feature: Equivalence
|
2
|
+
Background:
|
3
|
+
Given the JSON is:
|
4
|
+
"""
|
5
|
+
{
|
6
|
+
"array": [
|
7
|
+
"json",
|
8
|
+
"spec"
|
9
|
+
],
|
10
|
+
"created_at": "2011-07-08 02:27:34",
|
11
|
+
"empty_array": [
|
12
|
+
|
13
|
+
],
|
14
|
+
"empty_hash": {
|
15
|
+
},
|
16
|
+
"false": false,
|
17
|
+
"float": 10.0,
|
18
|
+
"hash": {
|
19
|
+
"json": "spec"
|
20
|
+
},
|
21
|
+
"id": 1,
|
22
|
+
"integer": 10,
|
23
|
+
"negative": -10,
|
24
|
+
"null": null,
|
25
|
+
"string": "jsontest",
|
26
|
+
"true": true,
|
27
|
+
"updated_at": "2011-07-08 02:28:50"
|
28
|
+
}
|
29
|
+
"""
|
30
|
+
|
31
|
+
Scenario: Identical JSON
|
32
|
+
When I get the JSON
|
33
|
+
Then the JSON should be:
|
34
|
+
"""
|
35
|
+
{
|
36
|
+
"array": [
|
37
|
+
"json",
|
38
|
+
"spec"
|
39
|
+
],
|
40
|
+
"created_at": "2011-07-08 02:27:34",
|
41
|
+
"empty_array": [
|
42
|
+
|
43
|
+
],
|
44
|
+
"empty_hash": {
|
45
|
+
},
|
46
|
+
"false": false,
|
47
|
+
"float": 10.0,
|
48
|
+
"hash": {
|
49
|
+
"json": "spec"
|
50
|
+
},
|
51
|
+
"id": 1,
|
52
|
+
"integer": 10,
|
53
|
+
"negative": -10,
|
54
|
+
"null": null,
|
55
|
+
"string": "jsontest",
|
56
|
+
"true": true,
|
57
|
+
"updated_at": "2011-07-08 02:28:50"
|
58
|
+
}
|
59
|
+
"""
|
60
|
+
|
61
|
+
Scenario: Reverse order
|
62
|
+
When I get the JSON
|
63
|
+
Then the JSON should be:
|
64
|
+
"""
|
65
|
+
{
|
66
|
+
"updated_at": "2011-07-08 02:28:50",
|
67
|
+
"true": true,
|
68
|
+
"string": "jsontest",
|
69
|
+
"null": null,
|
70
|
+
"negative": -10,
|
71
|
+
"integer": 10,
|
72
|
+
"id": 1,
|
73
|
+
"hash": {
|
74
|
+
"json": "spec"
|
75
|
+
},
|
76
|
+
"float": 10.0,
|
77
|
+
"false": false,
|
78
|
+
"empty_hash": {
|
79
|
+
},
|
80
|
+
"empty_array": [
|
81
|
+
|
82
|
+
],
|
83
|
+
"created_at": "2011-07-08 02:27:34",
|
84
|
+
"array": [
|
85
|
+
"json",
|
86
|
+
"spec"
|
87
|
+
]
|
88
|
+
}
|
89
|
+
"""
|
90
|
+
|
91
|
+
Scenario: Excluding keys
|
92
|
+
When I get the JSON
|
93
|
+
Then the JSON should be:
|
94
|
+
"""
|
95
|
+
{
|
96
|
+
"array": [
|
97
|
+
"json",
|
98
|
+
"spec"
|
99
|
+
],
|
100
|
+
"empty_array": [
|
101
|
+
|
102
|
+
],
|
103
|
+
"empty_hash": {
|
104
|
+
},
|
105
|
+
"false": false,
|
106
|
+
"float": 10.0,
|
107
|
+
"hash": {
|
108
|
+
"json": "spec"
|
109
|
+
},
|
110
|
+
"integer": 10,
|
111
|
+
"negative": -10,
|
112
|
+
"null": null,
|
113
|
+
"string": "jsontest",
|
114
|
+
"true": true
|
115
|
+
}
|
116
|
+
"""
|
117
|
+
|
118
|
+
Scenario: String
|
119
|
+
When I get the JSON
|
120
|
+
Then the JSON at "string" should be "jsontest"
|
121
|
+
And the JSON at "string" should be:
|
122
|
+
"""
|
123
|
+
"jsontest"
|
124
|
+
"""
|
125
|
+
|
126
|
+
Scenario: Integer
|
127
|
+
When I get the JSON
|
128
|
+
Then the JSON at "integer" should be 10
|
129
|
+
And the JSON at "integer" should be:
|
130
|
+
"""
|
131
|
+
10
|
132
|
+
"""
|
133
|
+
|
134
|
+
Scenario: Negative integer
|
135
|
+
When I get the JSON
|
136
|
+
Then the JSON at "negative" should be -10
|
137
|
+
And the JSON at "negative" should be:
|
138
|
+
"""
|
139
|
+
-10
|
140
|
+
"""
|
141
|
+
|
142
|
+
Scenario: Float
|
143
|
+
When I get the JSON
|
144
|
+
Then the JSON at "float" should be 10.0
|
145
|
+
And the JSON at "float" should be 10.0e0
|
146
|
+
And the JSON at "float" should be 10.0e+0
|
147
|
+
And the JSON at "float" should be 10.0e-0
|
148
|
+
And the JSON at "float" should be 10e0
|
149
|
+
And the JSON at "float" should be 10e+0
|
150
|
+
And the JSON at "float" should be 10e-0
|
151
|
+
And the JSON at "float" should be 1.0e1
|
152
|
+
And the JSON at "float" should be 1.0e+1
|
153
|
+
And the JSON at "float" should be 1e1
|
154
|
+
And the JSON at "float" should be 1e+1
|
155
|
+
And the JSON at "float" should be 100.0e-1
|
156
|
+
And the JSON at "float" should be 100e-1
|
157
|
+
And the JSON at "float" should be:
|
158
|
+
"""
|
159
|
+
10.0
|
160
|
+
"""
|
161
|
+
|
162
|
+
Scenario: Array
|
163
|
+
When I get the JSON
|
164
|
+
Then the JSON at "array" should be ["json","spec"]
|
165
|
+
And the JSON at "array/0" should be "json"
|
166
|
+
And the JSON at "array/1" should be "spec"
|
167
|
+
And the JSON at "array" should be:
|
168
|
+
"""
|
169
|
+
[
|
170
|
+
"json",
|
171
|
+
"spec"
|
172
|
+
]
|
173
|
+
"""
|
174
|
+
|
175
|
+
Scenario: Empty array
|
176
|
+
When I get the JSON
|
177
|
+
Then the JSON at "empty_array" should be []
|
178
|
+
And the JSON at "empty_array" should be:
|
179
|
+
"""
|
180
|
+
[
|
181
|
+
|
182
|
+
]
|
183
|
+
"""
|
184
|
+
|
185
|
+
Scenario: Hash
|
186
|
+
When I get the JSON
|
187
|
+
Then the JSON at "hash" should be {"json":"spec"}
|
188
|
+
And the JSON at "hash/json" should be "spec"
|
189
|
+
And the JSON at "hash" should be:
|
190
|
+
"""
|
191
|
+
{
|
192
|
+
"json": "spec"
|
193
|
+
}
|
194
|
+
"""
|
195
|
+
|
196
|
+
Scenario: Empty hash
|
197
|
+
When I get the JSON
|
198
|
+
Then the JSON at "empty_hash" should be {}
|
199
|
+
And the JSON at "empty_hash" should be:
|
200
|
+
"""
|
201
|
+
{
|
202
|
+
}
|
203
|
+
"""
|
204
|
+
|
205
|
+
Scenario: True
|
206
|
+
When I get the JSON
|
207
|
+
Then the JSON at "true" should be true
|
208
|
+
And the JSON at "true" should be:
|
209
|
+
"""
|
210
|
+
true
|
211
|
+
"""
|
212
|
+
|
213
|
+
Scenario: False
|
214
|
+
When I get the JSON
|
215
|
+
Then the JSON at "false" should be false
|
216
|
+
And the JSON at "false" should be:
|
217
|
+
"""
|
218
|
+
false
|
219
|
+
"""
|
220
|
+
|
221
|
+
Scenario: Null
|
222
|
+
When I get the JSON
|
223
|
+
Then the JSON at "null" should be null
|
224
|
+
And the JSON at "null" should be:
|
225
|
+
"""
|
226
|
+
null
|
227
|
+
"""
|
228
|
+
|
229
|
+
Scenario: Excluded value
|
230
|
+
When I get the JSON
|
231
|
+
Then the JSON at "created_at" should be "2011-07-08 02:27:34"
|
232
|
+
And the JSON at "id" should be 1
|
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 | "jsontest" |
|
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" |
|
260
|
+
|
261
|
+
@fail
|
262
|
+
Scenario: Table format can fail equivalence
|
263
|
+
When I get the JSON
|
264
|
+
Then the JSON should have the following:
|
265
|
+
| array | ["bad","garbage"] |
|
266
|
+
| array/0 | "json" |
|
267
|
+
| array/1 | "spec" |
|
268
|
+
| created_at | "2011-07-08 02:27:34" |
|
269
|
+
| empty_array | [] |
|
270
|
+
| empty_hash | {} |
|
271
|
+
| false | false |
|
272
|
+
| float | 10.0 |
|
273
|
+
| hash | {"json":"spec"} |
|
274
|
+
| hash/json | "spec" |
|
275
|
+
| id | 1 |
|
276
|
+
| integer | 10 |
|
277
|
+
| negative | -10 |
|
278
|
+
| null | null |
|
279
|
+
| string | "jsontest" |
|
280
|
+
| true | true |
|
281
|
+
| updated_at | "2011-07-08 02:28:50" |
|
282
|
+
And the JSON at "array" should have the following:
|
283
|
+
| should | "fail" |
|
284
|
+
| 1 | "spec" |
|
285
|
+
And the JSON at "hash" should have the following:
|
286
|
+
| random | "junk" |
|