jason_spec 0.0.1 → 0.0.2
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/.travis.yml +6 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +35 -10
- data/VERSION +1 -1
- data/jason_spec.gemspec +76 -0
- data/lib/jason/spec.rb +19 -19
- metadata +20 -18
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# jason_spec
|
2
2
|
|
3
|
+
[](https://travis-ci.org/OrganisedMinds/jason_spec)
|
4
|
+
|
3
5
|
Write specs for JSON without writing JSON or data-structures
|
4
6
|
|
5
7
|
<a href="http://www.flickr.com/photos/frogdna/5534481247/" title="Friday the 13th - Jason Mask Replica by frogDNA, on Flickr"><img src="http://farm6.staticflickr.com/5094/5534481247_361aa64980.jpg" width="375" height="500" alt="Friday the 13th - Jason Mask Replica"></a>
|
@@ -23,7 +25,9 @@ means you should not type or create any JSON; or even data structures.
|
|
23
25
|
The following snippet:
|
24
26
|
|
25
27
|
```ruby
|
26
|
-
%q(
|
28
|
+
%q(
|
29
|
+
{"first_name":"Jason","last_name":"Voorhees"}
|
30
|
+
).should have_jason([:first_name,:last_name])
|
27
31
|
```
|
28
32
|
|
29
33
|
would result in a match. The supplied JSON has a `:first_name` and a
|
@@ -32,7 +36,9 @@ would result in a match. The supplied JSON has a `:first_name` and a
|
|
32
36
|
Off course, you can also specify your root object:
|
33
37
|
|
34
38
|
```ruby
|
35
|
-
%q(
|
39
|
+
%q(
|
40
|
+
{"movie":{"title":"Friday the 13th","release_year":"1980"}}
|
41
|
+
).should have_jason(
|
36
42
|
movie: [ :title, :release_year ]
|
37
43
|
)
|
38
44
|
```
|
@@ -47,7 +53,9 @@ object in the specifications key, like so:
|
|
47
53
|
|
48
54
|
my_movie = Movie.find(x)
|
49
55
|
|
50
|
-
%q(
|
56
|
+
%q(
|
57
|
+
{"movie":{"title":"Friday the 13th","release_year":"1980"}}
|
58
|
+
).should have_jason(
|
51
59
|
{ movie: { my_movie => [ :title, :release_year ] } }
|
52
60
|
)
|
53
61
|
```
|
@@ -64,7 +72,9 @@ specification?
|
|
64
72
|
**Jason::Spec** to the resque:
|
65
73
|
|
66
74
|
```ruby
|
67
|
-
%q(
|
75
|
+
%q(
|
76
|
+
{"movies":[{"title":"Friday the 13th"},{"title":"Nightmare on Elm Street"}]}
|
77
|
+
).should have_jason(
|
68
78
|
movies: Jason.spec( type: Array, size: 2, each: [ :title ] )
|
69
79
|
)
|
70
80
|
```
|
@@ -97,21 +107,36 @@ json.should have_jason(
|
|
97
107
|
)
|
98
108
|
```
|
99
109
|
|
110
|
+
For further documentation, please read the docs at [RubyDoc.info](http://rubydoc.info/gems/jason_spec)
|
111
|
+
|
100
112
|
## State
|
101
113
|
|
102
|
-
|
114
|
+
The examples in this readme work, see `spec/readme_spec.rb`. Otherwise this is
|
115
|
+
a work in progress; Especialy the features on `Jason::Spec` are bound to grow.
|
116
|
+
|
117
|
+
## Credits
|
103
118
|
|
104
|
-
|
119
|
+
`jason_spec`
|
120
|
+
* was inspired by [json_spec](https://github.com/collectiveidea/json_spec).
|
121
|
+
The code organisation has been derived from their project.
|
122
|
+
* was written by [Hartog de Mik](https://github.com/coffeeaddict)
|
123
|
+
* was kindly sponsored by [OrganisedMinds](http://www.organisedminds.com/)
|
124
|
+
For those who organise Teamwork
|
105
125
|
|
106
126
|
## Contributing to jason_spec
|
107
127
|
|
108
|
-
* Check out the latest master to make sure the feature hasn't been implemented
|
109
|
-
|
128
|
+
* Check out the latest master to make sure the feature hasn't been implemented
|
129
|
+
or the bug hasn't been fixed yet.
|
130
|
+
* Check out the issue tracker to make sure someone already hasn't requested
|
131
|
+
it and/or contributed it.
|
110
132
|
* Fork the project.
|
111
133
|
* Start a feature/bugfix branch.
|
112
134
|
* Commit and push until you are happy with your contribution.
|
113
|
-
* Make sure to add tests for it. This is important so I don't break it in a
|
114
|
-
|
135
|
+
* Make sure to add tests for it. This is important so I don't break it in a
|
136
|
+
future version unintentionally.
|
137
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to
|
138
|
+
have your own version, or is otherwise necessary, that is fine, but please
|
139
|
+
isolate to its own commit so I can cherry-pick around it.
|
115
140
|
|
116
141
|
## Copyright
|
117
142
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/jason_spec.gemspec
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "jason_spec"
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Hartog C. de Mik"]
|
12
|
+
s.date = "2013-12-04"
|
13
|
+
s.description = "Write specifications for the expected json, without writing json"
|
14
|
+
s.email = "hartog@organisedminds.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
".travis.yml",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"jason_spec.gemspec",
|
30
|
+
"lib/jason/have_jason_matcher.rb",
|
31
|
+
"lib/jason/matchers.rb",
|
32
|
+
"lib/jason/spec.rb",
|
33
|
+
"lib/jason_spec.rb",
|
34
|
+
"spec/have_jason_matcher_spec.rb",
|
35
|
+
"spec/jason_spec_spec.rb",
|
36
|
+
"spec/matchers_spec.rb",
|
37
|
+
"spec/readme_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
s.homepage = "http://github.com/coffeeaddict/jason_spec"
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = "1.8.11"
|
44
|
+
s.summary = "Spec your JSON"
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<rufus-json>, ["= 1.0.6"])
|
51
|
+
s.add_runtime_dependency(%q<rspec>, ["~> 2.8"])
|
52
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
53
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
|
56
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rufus-json>, ["= 1.0.6"])
|
59
|
+
s.add_dependency(%q<rspec>, ["~> 2.8"])
|
60
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
61
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
64
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rufus-json>, ["= 1.0.6"])
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 2.8"])
|
69
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
70
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
71
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
72
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
73
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
data/lib/jason/spec.rb
CHANGED
@@ -117,19 +117,19 @@ module Jason
|
|
117
117
|
# @return [void]
|
118
118
|
#
|
119
119
|
# @example Shallow check for key
|
120
|
-
#
|
120
|
+
# match_each([ :id ], [ { 'id' => 1 }])
|
121
121
|
#
|
122
122
|
# @example Shallow check for key with any
|
123
|
-
#
|
123
|
+
# match_each([ :id ], [ { 'id' => 1 }, { 'bar' => 'beer' } ], :any )
|
124
124
|
#
|
125
125
|
# @example Shallow check for key with none
|
126
|
-
#
|
126
|
+
# not match_each([ :id ], [ { 'id' => 1 }, { 'bar' => 'beer' } ], :any )
|
127
127
|
#
|
128
128
|
# @example Deep check
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
129
|
+
# match_each(
|
130
|
+
# { item: [ :id, :name ] }
|
131
|
+
# [ { "item" => { "id" => "one", "name" => "two" } } ]
|
132
|
+
# )
|
133
133
|
#
|
134
134
|
def match_each(mapping, value, type=:each, root="")
|
135
135
|
misses = []
|
@@ -220,24 +220,24 @@ module Jason
|
|
220
220
|
# @return [void]
|
221
221
|
#
|
222
222
|
# @example Using array (each)
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
223
|
+
# # every field must be present
|
224
|
+
# spec = Jason.spec(fields: [ :id, :name ])
|
225
|
+
# spec.fits({ 'id' => 1, 'name' => "jason" })
|
226
|
+
# not spec.fits({ 'id' => 1 })
|
227
227
|
#
|
228
228
|
# @example Using each
|
229
|
-
#
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
229
|
+
# # same as passing the array
|
230
|
+
# spec = Jason.spec(fields: { each: [ :id, :name ] })
|
231
|
+
# spec.fits({ 'id' => 1, 'name' => "jason" })
|
232
|
+
# not spec.fits({ 'id' => 1 })
|
233
233
|
#
|
234
234
|
# @example Using any
|
235
|
-
#
|
236
|
-
#
|
235
|
+
# spec = Jason.spec(fields: { any: [ :id, :name ] })
|
236
|
+
# spec.fits({ 'id' => 1 })
|
237
237
|
#
|
238
238
|
# @example Using none
|
239
|
-
#
|
240
|
-
#
|
239
|
+
# spec = Jason.spec(fields: { none: [ :id, :name ] })
|
240
|
+
# not spec.fits({ 'id' => 1 })
|
241
241
|
#
|
242
242
|
def match_fields(fields, value, type=:each)
|
243
243
|
if fields.is_a?(Hash)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jason_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rufus-json
|
16
|
-
requirement: &
|
16
|
+
requirement: &11464600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: 1.0.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11464600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &11460260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.8
|
32
|
+
version: '2.8'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *11460260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yard
|
38
|
-
requirement: &
|
38
|
+
requirement: &11483160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.7'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *11483160
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &11495740 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.12'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *11495740
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &11492680 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *11492680
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &11491600 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.8.7
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *11491600
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: simplecov
|
82
|
-
requirement: &
|
82
|
+
requirement: &11503240 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *11503240
|
91
91
|
description: Write specifications for the expected json, without writing json
|
92
92
|
email: hartog@organisedminds.com
|
93
93
|
executables: []
|
@@ -98,12 +98,14 @@ extra_rdoc_files:
|
|
98
98
|
files:
|
99
99
|
- .document
|
100
100
|
- .rspec
|
101
|
+
- .travis.yml
|
101
102
|
- Gemfile
|
102
103
|
- Gemfile.lock
|
103
104
|
- LICENSE.txt
|
104
105
|
- README.md
|
105
106
|
- Rakefile
|
106
107
|
- VERSION
|
108
|
+
- jason_spec.gemspec
|
107
109
|
- lib/jason/have_jason_matcher.rb
|
108
110
|
- lib/jason/matchers.rb
|
109
111
|
- lib/jason/spec.rb
|
@@ -128,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
130
|
version: '0'
|
129
131
|
segments:
|
130
132
|
- 0
|
131
|
-
hash: -
|
133
|
+
hash: -654740456178781796
|
132
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
135
|
none: false
|
134
136
|
requirements:
|