json_matchers 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45d20c593cd3b650c0d213060ae783752c50f104
4
- data.tar.gz: 21bea88fedfc1e3f024fff3f235f4e9fe3dda5c4
3
+ metadata.gz: 7837005397def477004c328fc25ebf08f3442338
4
+ data.tar.gz: 6eabcabe3f0317d35ed02980b67d615e609933cd
5
5
  SHA512:
6
- metadata.gz: f16c63ae61ba9c9a153c715a30bd9c2ba0c75b95f639a4a7a12797c7a9056d757396ccc2504761e1fd75c39a5b0cffe8bca09252672cdfbbd40493436187e279
7
- data.tar.gz: f9dcac8c1ea5c8d35c91322f7b492c8e9acec5e180426d31c73d7616256ea9a12ea54050dd12c10ffe233bfbf60478d9fd7443fff92da6c74d537a549e4b8c56
6
+ metadata.gz: 463f19a601e24f35a43ca210636c9e68f80c6f33b5c3e402d4116a5e3bd9c60748a4df8755da1edbde4d570b48453a15bbcd76dccc42d3a643a8d26fe87f5820
7
+ data.tar.gz: fba3346e93283c75f917bfa3ee9fd49a1680f1767ef97a701a439eb9aed4596400b929c78b95c0effffc59547eede894a2d1ae67710297ee2e8eef49632f7640
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml CHANGED
@@ -4,4 +4,4 @@ language: ruby
4
4
  notifications:
5
5
  email: false
6
6
  rvm:
7
- - 2.2.0
7
+ - 2.3.0
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ ruby "2.3.0"
4
+
3
5
  # Specify your gem's dependencies in shoulda-matchers-json.gemspec
4
6
  gemspec
data/NEWS.md CHANGED
@@ -1,6 +1,13 @@
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
+
4
11
  0.5.1
5
12
  =====
6
13
 
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 your response against your schema with `match_response_schema`
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:
@@ -8,11 +8,9 @@ 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.body,
13
+ json_from(response).to_s,
16
14
  options,
17
15
  )
18
16
  rescue JSON::Schema::ValidationError => ex
@@ -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
@@ -1,3 +1,3 @@
1
1
  module JsonMatchers
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  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",
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.5.1
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: 2016-03-19 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -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.4.5.1
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
@@ -147,3 +148,4 @@ test_files:
147
148
  - spec/json_matchers/match_response_schema_spec.rb
148
149
  - spec/spec_helper.rb
149
150
  - spec/support/file_helpers.rb
151
+ has_rdoc: