json_matchers 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf14bd2b66049174e62c9b50f750692f761cb66c
4
- data.tar.gz: 1ceafe472e8e7225bb194ad49fa5c17676800a13
3
+ metadata.gz: 38d9e1c499434062adc03c1129a466b7305d7eda
4
+ data.tar.gz: e319990f5e9adaf73ea586658e936c37fcaf8b73
5
5
  SHA512:
6
- metadata.gz: 58d81f70e226218c2fe359f131414cb8740963156ebc16b0616b43b5e7d2f976a3c2b465b4b4460dc0853cb69a91866697f0e06e1397c43fc478a532f0c3e8d5
7
- data.tar.gz: 3a0d68faa322b689dc8331cf238bb5779e943d7854078b75b0627fac0e9037024627dfd6d49227a4b4e4e12e0405a87672cbe856c9e4e208c6086d53ba42a816
6
+ metadata.gz: f77e49e28fb5feb4b93960ae86810d0cebbfbe1d0f6657402f2ceb2f38b23fa989cd6696eea29705cdc910bdb869de17eed41e3bfd6a88e51ce1674a5899cd09
7
+ data.tar.gz: 8e6dda357800988ca2a32c4a8de459114f93584b9fe8cb12439a9d04d4a223bc7a5d90276c754df23c2203ab451f903a61025df1bec8adf3860424acfa7592cc
data/NEWS.md CHANGED
@@ -1,6 +1,14 @@
1
1
  master
2
2
  ======
3
3
 
4
+ 0.7.1
5
+ =====
6
+
7
+ * Accept Hash instances as arguments to `match_response_schema` [#58], [#59]
8
+
9
+ [#58]: https://github.com/thoughtbot/json_matchers/pull/58
10
+ [#59]: https://github.com/thoughtbot/json_matchers/pull/59
11
+
4
12
  0.7.0
5
13
  =====
6
14
 
data/README.md CHANGED
@@ -107,7 +107,7 @@ A list of available options can be found [here][options].
107
107
 
108
108
  [options]: https://github.com/ruby-json-schema/json-schema/blob/2.2.4/lib/json-schema/validator.rb#L160-L162
109
109
 
110
- ### Default matcher options
110
+ ### Global matcher options
111
111
 
112
112
  To configure the default options passed to *all* matchers, call
113
113
  `JsonMatchers.configure`:
@@ -122,7 +122,10 @@ end
122
122
 
123
123
  A list of available options can be found [here][options].
124
124
 
125
- [options]: https://github.com/ruby-json-schema/json-schema/blob/2.2.4/lib/json-schema/validator.rb#L160-L162
125
+ ### Default matcher options
126
+
127
+ * `record_errors: true` - *NOTE* `json_matchers` will always set
128
+ `record_errors: true`. This cannot be overridden.
126
129
 
127
130
  ### Embedding other Schemas
128
131
 
@@ -8,12 +8,12 @@ module JsonMatchers
8
8
  end
9
9
 
10
10
  class Configuration
11
- attr_reader :options
12
-
13
11
  def initialize
14
- @options = {
15
- record_errors: true,
16
- }
12
+ @options = {}
13
+ end
14
+
15
+ def options
16
+ @options.merge!(record_errors: true)
17
17
  end
18
18
  end
19
19
  end
@@ -15,6 +15,8 @@ module JsonMatchers
15
15
  def extract_json_string(payload)
16
16
  if payload.respond_to?(:body)
17
17
  payload.body
18
+ elsif payload.respond_to?(:to_h)
19
+ payload.to_h.to_json
18
20
  else
19
21
  payload
20
22
  end
@@ -1,3 +1,4 @@
1
+ require "delegate"
1
2
  require "json_matchers"
2
3
  require "json_matchers/payload"
3
4
 
@@ -1,3 +1,3 @@
1
1
  module JsonMatchers
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -0,0 +1,9 @@
1
+ describe JsonMatchers, ".configure" do
2
+ it "ignores :record_errors configuration" do
3
+ with_options(record_errors: false) do
4
+ configured_options = JsonMatchers.configuration.options
5
+
6
+ expect(configured_options).to include(record_errors: true)
7
+ end
8
+ end
9
+ end
@@ -22,6 +22,40 @@ describe JsonMatchers, "#match_response_schema" do
22
22
  expect(response_for({})).not_to match_response_schema("foo_schema")
23
23
  end
24
24
 
25
+ context "when passed a Hash" do
26
+ it "validates when the schema matches" do
27
+ create_schema("foo_schema", {
28
+ "type" => "object",
29
+ "required" => [
30
+ "id",
31
+ ],
32
+ "properties" => {
33
+ "id" => { "type" => "number" },
34
+ },
35
+ "additionalProperties" => false,
36
+ })
37
+
38
+ expect({ "id" => 1 }).to match_response_schema("foo_schema")
39
+ end
40
+
41
+ it "fails with message when negated" do
42
+ create_schema("foo_schema", {
43
+ "type" => "object",
44
+ "required" => [
45
+ "id",
46
+ ],
47
+ "properties" => {
48
+ "id" => { "type" => "number" },
49
+ },
50
+ "additionalProperties" => false,
51
+ })
52
+
53
+ expect {
54
+ expect({ "id" => "1" }).to match_response_schema("foo_schema")
55
+ }.to raise_formatted_error(%{{ "type": "number" }})
56
+ end
57
+ end
58
+
25
59
  context "when JSON is a string" do
26
60
  before(:each) do
27
61
  create_schema("foo_schema", {
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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Doyle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-24 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -106,6 +106,7 @@ files:
106
106
  - lib/json_matchers/rspec.rb
107
107
  - lib/json_matchers/validator.rb
108
108
  - lib/json_matchers/version.rb
109
+ - spec/json_matchers/configuration_spec.rb
109
110
  - spec/json_matchers/match_response_schema_spec.rb
110
111
  - spec/spec_helper.rb
111
112
  - spec/support/configuration.rb
@@ -130,11 +131,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  version: '0'
131
132
  requirements: []
132
133
  rubyforge_project:
133
- rubygems_version: 2.5.1
134
+ rubygems_version: 2.6.13
134
135
  signing_key:
135
136
  specification_version: 4
136
137
  summary: Validate your Rails JSON API's JSON
137
138
  test_files:
139
+ - spec/json_matchers/configuration_spec.rb
138
140
  - spec/json_matchers/match_response_schema_spec.rb
139
141
  - spec/spec_helper.rb
140
142
  - spec/support/configuration.rb