json_matchers 0.7.1 → 0.7.2

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: 38d9e1c499434062adc03c1129a466b7305d7eda
4
- data.tar.gz: e319990f5e9adaf73ea586658e936c37fcaf8b73
3
+ metadata.gz: 55bb76610a71379a9b0644723605a728b25da73e
4
+ data.tar.gz: 478ee6d652882830ffd6f09f88c7499163732c16
5
5
  SHA512:
6
- metadata.gz: f77e49e28fb5feb4b93960ae86810d0cebbfbe1d0f6657402f2ceb2f38b23fa989cd6696eea29705cdc910bdb869de17eed41e3bfd6a88e51ce1674a5899cd09
7
- data.tar.gz: 8e6dda357800988ca2a32c4a8de459114f93584b9fe8cb12439a9d04d4a223bc7a5d90276c754df23c2203ab451f903a61025df1bec8adf3860424acfa7592cc
6
+ metadata.gz: 65f5fc41b21b2d858f7f7230d16ed537413868e684df40a46aed5d091706e238e64230449ae37ab0ec43b89fa10bee0416c7c634ae19d4316647727e314ed5a1
7
+ data.tar.gz: 1c447958803f30f2290d51287ba0386fc5ae4fe77b7646b090a1dce028058b3795404a36ffb86dc4635d2b5717830a3d62e62be1758b9b5251af42e5862abc2f
data/NEWS.md CHANGED
@@ -1,6 +1,13 @@
1
1
  master
2
2
  ======
3
3
 
4
+ 0.7.2
5
+ =====
6
+
7
+ * Accept Array instances as arguments to `match_response_schema` [#60]
8
+
9
+ [#60]: https://github.com/thoughtbot/json_matchers/issues/60
10
+
4
11
  0.7.1
5
12
  =====
6
13
 
@@ -15,8 +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
+ elsif payload.is_a?(Array) || payload.is_a?(Hash)
19
+ payload.to_json
20
20
  else
21
21
  payload
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module JsonMatchers
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -56,6 +56,45 @@ describe JsonMatchers, "#match_response_schema" do
56
56
  end
57
57
  end
58
58
 
59
+ context "when passed a Array" do
60
+ it "validates when the schema matches" do
61
+ create_schema("foo_schema", {
62
+ "type" => "array",
63
+ "items" => {
64
+ "required" => [
65
+ "id",
66
+ ],
67
+ "properties" => {
68
+ "id" => { "type" => "number" },
69
+ },
70
+ "additionalProperties" => false,
71
+ }
72
+ })
73
+
74
+ expect([{ "id" => 1 }]).to match_response_schema("foo_schema")
75
+ end
76
+
77
+ it "fails with message when negated" do
78
+ create_schema("foo_schema", {
79
+ "type" => "array",
80
+ "items" => {
81
+ "type" => "object",
82
+ "required" => [
83
+ "id",
84
+ ],
85
+ "properties" => {
86
+ "id" => { "type" => "number" },
87
+ },
88
+ "additionalProperties" => false,
89
+ }
90
+ })
91
+
92
+ expect {
93
+ expect([{ "id" => "1" }]).to match_response_schema("foo_schema")
94
+ }.to raise_formatted_error(%{{ "type": "number" }})
95
+ end
96
+ end
97
+
59
98
  context "when JSON is a string" do
60
99
  before(:each) do
61
100
  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.1
4
+ version: 0.7.2
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-09-29 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema