json_matchers 0.5.0 → 0.6.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 +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +1 -1
- data/Gemfile +2 -0
- data/NEWS.md +17 -0
- data/README.md +16 -1
- data/json_matchers.gemspec +1 -1
- data/lib/json_matchers/matcher.rb +10 -4
- data/lib/json_matchers/version.rb +1 -1
- data/spec/json_matchers/match_response_schema_spec.rb +16 -0
- data/spec/support/file_helpers.rb +2 -0
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7837005397def477004c328fc25ebf08f3442338
|
|
4
|
+
data.tar.gz: 6eabcabe3f0317d35ed02980b67d615e609933cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 463f19a601e24f35a43ca210636c9e68f80c6f33b5c3e402d4116a5e3bd9c60748a4df8755da1edbde4d570b48453a15bbcd76dccc42d3a643a8d26fe87f5820
|
|
7
|
+
data.tar.gz: fba3346e93283c75f917bfa3ee9fd49a1680f1767ef97a701a439eb9aed4596400b929c78b95c0effffc59547eede894a2d1ae67710297ee2e8eef49632f7640
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.3.0
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/NEWS.md
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
master
|
|
2
2
|
======
|
|
3
3
|
|
|
4
|
+
0.6.0
|
|
5
|
+
=====
|
|
6
|
+
|
|
7
|
+
* Accept a JSON string along with a `response`.
|
|
8
|
+
|
|
9
|
+
[#43]: https://github.com/thoughtbot/json_matchers/pull/43
|
|
10
|
+
|
|
11
|
+
0.5.1
|
|
12
|
+
=====
|
|
13
|
+
|
|
14
|
+
* Update `json-schema` dependency to `~> 2.6.0`. [#37]
|
|
15
|
+
|
|
16
|
+
[#37]: https://github.com/thoughtbot/json_matchers/pull/37
|
|
17
|
+
|
|
18
|
+
0.5.0
|
|
19
|
+
=====
|
|
20
|
+
|
|
4
21
|
Breaking Changes
|
|
5
22
|
----------------
|
|
6
23
|
|
data/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Define your [JSON Schema](http://json-schema.org/example1.html) in the schema di
|
|
|
56
56
|
}
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
Then, validate
|
|
59
|
+
Then, validate `response` against your schema with `match_response_schema`
|
|
60
60
|
|
|
61
61
|
```ruby
|
|
62
62
|
# spec/requests/posts_spec.rb
|
|
@@ -71,6 +71,21 @@ describe "GET /posts" do
|
|
|
71
71
|
end
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
Alternatively, `match_response_schema` accepts a string:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
# spec/requests/posts_spec.rb
|
|
78
|
+
|
|
79
|
+
describe "GET /posts" do
|
|
80
|
+
it "returns Posts" do
|
|
81
|
+
get posts_path, format: :json
|
|
82
|
+
|
|
83
|
+
expect(response.status).to eq 200
|
|
84
|
+
expect(response.body).to match_json_schema("posts")
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
```
|
|
88
|
+
|
|
74
89
|
### Passing options to the validator
|
|
75
90
|
|
|
76
91
|
The matcher accepts options, which it passes to the validator:
|
data/json_matchers.gemspec
CHANGED
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
spec.add_dependency("json-schema", "~> 2.
|
|
21
|
+
spec.add_dependency("json-schema", "~> 2.6.0")
|
|
22
22
|
spec.add_dependency("activesupport", '>= 3.0.0')
|
|
23
23
|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
|
@@ -8,17 +8,15 @@ module JsonMatchers
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def matches?(response)
|
|
11
|
-
@response = response
|
|
12
|
-
|
|
13
11
|
JSON::Validator.validate!(
|
|
14
12
|
schema_path.to_s,
|
|
15
|
-
response.
|
|
13
|
+
json_from(response).to_s,
|
|
16
14
|
options,
|
|
17
15
|
)
|
|
18
16
|
rescue JSON::Schema::ValidationError => ex
|
|
19
17
|
@validation_failure_message = ex.message
|
|
20
18
|
false
|
|
21
|
-
rescue JSON::
|
|
19
|
+
rescue JSON::Schema::JsonParseError
|
|
22
20
|
raise InvalidSchemaError
|
|
23
21
|
end
|
|
24
22
|
|
|
@@ -29,5 +27,13 @@ module JsonMatchers
|
|
|
29
27
|
private
|
|
30
28
|
|
|
31
29
|
attr_reader :schema_path, :options
|
|
30
|
+
|
|
31
|
+
def json_from(response)
|
|
32
|
+
if response.respond_to?(:body)
|
|
33
|
+
response.body
|
|
34
|
+
else
|
|
35
|
+
response
|
|
36
|
+
end
|
|
37
|
+
end
|
|
32
38
|
end
|
|
33
39
|
end
|
|
@@ -39,6 +39,22 @@ describe JsonMatchers, "#match_response_schema" do
|
|
|
39
39
|
to match_response_schema("foo_schema", strict: false)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
it "validates a JSON string" do
|
|
43
|
+
create_schema("foo_schema", {
|
|
44
|
+
"type" => "object",
|
|
45
|
+
"required" => [
|
|
46
|
+
"id",
|
|
47
|
+
],
|
|
48
|
+
"properties" => {
|
|
49
|
+
"id" => { "type" => "number" },
|
|
50
|
+
},
|
|
51
|
+
"additionalProperties" => false,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
expect(response_for({ "id" => 1 }).body).
|
|
55
|
+
to match_response_schema("foo_schema")
|
|
56
|
+
end
|
|
57
|
+
|
|
42
58
|
it "fails when the body contains a property with the wrong type" do
|
|
43
59
|
create_schema("foo_schema", {
|
|
44
60
|
"type" => "object",
|
|
@@ -30,6 +30,8 @@ end
|
|
|
30
30
|
RSpec.configure do |config|
|
|
31
31
|
config.include FileHelpers
|
|
32
32
|
|
|
33
|
+
config.before(:each) { JSON::Validator.clear_cache }
|
|
34
|
+
|
|
33
35
|
config.around do |example|
|
|
34
36
|
JsonMatchers.schema_root = File.join(Dir.pwd, "spec", "fixtures", "schemas")
|
|
35
37
|
FileUtils.mkdir_p(JsonMatchers.schema_root)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: json_matchers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sean Doyle
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-10-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json-schema
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 2.
|
|
19
|
+
version: 2.6.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 2.
|
|
26
|
+
version: 2.6.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: activesupport
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -103,6 +103,7 @@ extra_rdoc_files: []
|
|
|
103
103
|
files:
|
|
104
104
|
- ".gitignore"
|
|
105
105
|
- ".rspec"
|
|
106
|
+
- ".ruby-version"
|
|
106
107
|
- ".travis.yml"
|
|
107
108
|
- CONTRIBUTING.md
|
|
108
109
|
- Gemfile
|
|
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
139
140
|
version: '0'
|
|
140
141
|
requirements: []
|
|
141
142
|
rubyforge_project:
|
|
142
|
-
rubygems_version: 2.5.
|
|
143
|
+
rubygems_version: 2.5.1
|
|
143
144
|
signing_key:
|
|
144
145
|
specification_version: 4
|
|
145
146
|
summary: Validate your Rails JSON API's JSON
|