pact-support 1.7.1 → 1.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: fc9f8683f2295ada09a03f4726ac8c8532d2def6
4
- data.tar.gz: c5796a44f6c28c2070cb37e1ae8d6341e2118463
3
+ metadata.gz: 6c575784ba0803bdeccb12e271ffdec723771497
4
+ data.tar.gz: a81a629772d07d9ba46da3be40d461a4906c667c
5
5
  SHA512:
6
- metadata.gz: fb794ca126e1566123ab1c7333fb32d3e66851aed50b7f2489b6979380baf802e09cda256fa2806ebffeba3a93371e5627029aa6d515c6e4912b125e457758a8
7
- data.tar.gz: 862c5fc5b00ddc050e22337565acbae72a72bcd9845767dffed811aca2cdbeb79b124d3a681d40ab0b5fdf6cdec6705970694c6794aac6b7189880a2bef2ac61
6
+ metadata.gz: af8f2fd481a2b5886b6369883d1f4ea696406d16cfc55024958116cc2b170548e4271a1a37125ceddba76be643bf2a8c58ac7d4e5fd17f2fc887002e085a360d
7
+ data.tar.gz: 31127041531129db0c31928c8c17bedf54566133bf886725e6db5285a9676c19185767f5f86ff784a7a5a1cfdcf059564e5eae08a5b693c63ce77d5d247e8bc5
@@ -1,3 +1,12 @@
1
+ <a name="v1.7.2"></a>
2
+ ### v1.7.2 (2018-08-09)
3
+
4
+
5
+ #### Bug Fixes
6
+
7
+ * correctly handle Pact.like and Pact.each_like at top level of body ([f37c283](/../../commit/f37c283))
8
+
9
+
1
10
  <a name="v1.7.1"></a>
2
11
  ### v1.7.1 (2018-08-09)
3
12
 
@@ -31,36 +31,44 @@ module Pact
31
31
  end
32
32
 
33
33
  def recurse expected, path
34
- case expected
34
+ recursed = case expected
35
35
  when Hash then recurse_hash(expected, path)
36
36
  when Array then recurse_array(expected, path)
37
37
  else
38
38
  expected
39
39
  end
40
+ wrap(recursed, path)
40
41
  end
41
42
 
42
43
  def recurse_hash hash, path
43
44
  hash.each_with_object({}) do | (k, v), new_hash |
44
45
  new_path = path + "['#{k}']"
45
- new_hash[k] = recurse(wrap(v, new_path), new_path)
46
+ new_hash[k] = recurse(v, new_path)
46
47
  end
47
48
  end
48
49
 
49
50
  def recurse_array array, path
50
-
51
- parent_match_rule = @matching_rules[path] && @matching_rules[path]['matchers'] && @matching_rules[path]['matchers'].first && @matching_rules[path]['matchers'].first.delete('match')
51
+ # This assumes there is only one rule! TODO make this find the appropriate rule.
52
+ parent_match_rule = @matching_rules[path]['matchers'].first['match'] rescue nil
52
53
  array_like_children_path = "#{path}[*]*"
53
- children_match_rule = @matching_rules[array_like_children_path] && @matching_rules[array_like_children_path]['matchers'] && @matching_rules[array_like_children_path]['matchers'].first && @matching_rules[array_like_children_path]['matchers'].first.delete('match')
54
- min = @matching_rules[path] && @matching_rules[path]['matchers'] && @matching_rules[path]['matchers'].first && @matching_rules[path]['matchers'].first.delete('min')
54
+ children_match_rule = @matching_rules[array_like_children_path]['matchers'].first['match'] rescue nil
55
+ min = @matching_rules[path]['matchers'].first['min'] rescue nil
55
56
 
56
- if min && (children_match_rule == 'type' || (children_match_rule.nil? && parent_match_rule == 'type'))
57
+ if min && children_match_rule == 'type'
58
+ @matching_rules[path]['matchers'].first.delete('min')
59
+ @matching_rules[array_like_children_path]['matchers'].first.delete('match')
60
+ warn_when_not_one_example_item(array, path)
61
+ Pact::ArrayLike.new(recurse(array.first, "#{path}[*]"), min: min)
62
+ elsif min && parent_match_rule == 'type'
63
+ @matching_rules[path]['matchers'].first.delete('min')
64
+ @matching_rules[path]['matchers'].first.delete('match')
57
65
  warn_when_not_one_example_item(array, path)
58
66
  Pact::ArrayLike.new(recurse(array.first, "#{path}[*]"), min: min)
59
67
  else
60
68
  new_array = []
61
69
  array.each_with_index do | item, index |
62
70
  new_path = path + "[#{index}]"
63
- new_array << recurse(wrap(item, new_path), new_path)
71
+ new_array << recurse(item, new_path)
64
72
  end
65
73
  new_array
66
74
  end
@@ -82,14 +90,13 @@ module Pact
82
90
  elsif rules['regex']
83
91
  handle_regex(object, path, rules)
84
92
  else
85
- #log_ignored_rules(path, rules, {})
86
93
  object
87
94
  end
88
95
  end
89
96
 
90
97
  def handle_match_type object, path, rules
91
98
  rules.delete('match')
92
- Pact::SomethingLike.new(recurse(object, path))
99
+ Pact::SomethingLike.new(object)
93
100
  end
94
101
 
95
102
  def handle_regex object, path, rules
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "1.7.1"
3
+ VERSION = "1.7.2"
4
4
  end
5
5
  end
@@ -160,149 +160,169 @@ module Pact
160
160
  end
161
161
  end
162
162
 
163
- describe "with an array where all elements should match by type and the rule is specified on the parent element and there is no min specified" do
163
+ describe "with an ArrayLike containing a Term" do
164
164
  let(:expected) do
165
- {
166
- 'alligators' => [{'name' => 'Mary'}]
167
- }
165
+ ["foo"]
168
166
  end
169
167
 
170
168
  let(:matching_rules) do
171
169
  {
172
- "$.body.alligators" => { 'match' => 'type' }
170
+ "$.body" => {"min" => 1},
171
+ "$.body[*].*" => {"match" => "type"},
172
+ "$.body[*]" => {"match" => "regex", "regex"=>"f"}
173
173
  }
174
174
  end
175
175
 
176
- it "creates a Pact::SomethingLike at the appropriate path" do
177
- expect(subject["alligators"]).to be_instance_of(Pact::SomethingLike)
178
- expect(subject["alligators"].contents).to eq ['name' => 'Mary']
176
+ it "it creates an ArrayLike with a Pact::Term as the contents" do
177
+ expect(subject).to be_a(Pact::ArrayLike)
178
+ expect(subject.contents).to be_a(Pact::Term)
179
179
  end
180
180
  end
181
+ end
181
182
 
182
- describe "with an array where all elements should match by type and the rule is specified on the child elements" do
183
- let(:expected) do
184
- {
185
- 'alligators' => [{'name' => 'Mary'}]
186
- }
187
- end
183
+ describe "with an array where all elements should match by type and the rule is specified on the parent element and there is no min specified" do
184
+ let(:expected) do
185
+ {
186
+ 'alligators' => [{'name' => 'Mary'}]
187
+ }
188
+ end
188
189
 
189
- let(:matching_rules) do
190
- {
191
- "$.body.alligators" => { 'min' => 2 },
192
- "$.body.alligators[*].*" => { 'match' => 'type'}
193
- }
194
- end
190
+ let(:matching_rules) do
191
+ {
192
+ "$.body.alligators" => { 'match' => 'type' }
193
+ }
194
+ end
195
195
 
196
- it "creates a Pact::ArrayLike at the appropriate path" do
197
- expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
198
- expect(subject["alligators"].contents).to eq 'name' => 'Mary'
199
- expect(subject["alligators"].min).to eq 2
200
- end
196
+ it "creates a Pact::SomethingLike at the appropriate path" do
197
+ expect(subject["alligators"]).to be_instance_of(Pact::SomethingLike)
198
+ expect(subject["alligators"].contents).to eq ['name' => 'Mary']
201
199
  end
200
+ end
202
201
 
203
- describe "with an array where all elements should match by type and the rule is specified on both the parent element and the child elements" do
204
- let(:expected) do
205
- {
206
- 'alligators' => [{'name' => 'Mary'}]
207
- }
208
- end
202
+ describe "with an array where all elements should match by type and the rule is specified on the child elements" do
203
+ let(:expected) do
204
+ {
205
+ 'alligators' => [{'name' => 'Mary'}]
206
+ }
207
+ end
209
208
 
210
- let(:matching_rules) do
211
- {
212
- "$.body.alligators" => { 'min' => 2, 'match' => 'type' },
213
- "$.body.alligators[*].*" => { 'match' => 'type'}
214
- }
215
- end
209
+ let(:matching_rules) do
210
+ {
211
+ "$.body.alligators" => { 'min' => 2 },
212
+ "$.body.alligators[*].*" => { 'match' => 'type'}
213
+ }
214
+ end
216
215
 
217
- it "creates a Pact::ArrayLike at the appropriate path" do
218
- expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
219
- expect(subject["alligators"].contents).to eq 'name' => 'Mary'
220
- expect(subject["alligators"].min).to eq 2
221
- end
216
+ it "creates a Pact::ArrayLike at the appropriate path" do
217
+ expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
218
+ expect(subject["alligators"].contents).to eq 'name' => 'Mary'
219
+ expect(subject["alligators"].min).to eq 2
222
220
  end
221
+ end
223
222
 
224
- describe "with an array where all elements should match by type and there is only a match:type on the parent element" do
225
- let(:expected) do
226
- {
227
- 'alligators' => [{'name' => 'Mary'}]
228
- }
229
- end
223
+ describe "with an array where all elements should match by type and the rule is specified on both the parent element and the child elements" do
224
+ let(:expected) do
225
+ {
226
+ 'alligators' => [{'name' => 'Mary'}]
227
+ }
228
+ end
230
229
 
231
- let(:matching_rules) do
232
- {
233
- "$.body.alligators" => { 'min' => 2, 'match' => 'type' },
234
- }
235
- end
230
+ let(:matching_rules) do
231
+ {
232
+ "$.body.alligators" => { 'min' => 2, 'match' => 'type' },
233
+ "$.body.alligators[*].*" => { 'match' => 'type'}
234
+ }
235
+ end
236
236
 
237
- it "creates a Pact::ArrayLike at the appropriate path" do
238
- expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
239
- expect(subject["alligators"].contents).to eq 'name' => 'Mary'
240
- expect(subject["alligators"].min).to eq 2
241
- end
237
+ it "creates a Pact::ArrayLike at the appropriate path" do
238
+ expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
239
+ expect(subject["alligators"].contents).to eq 'name' => 'Mary'
240
+ expect(subject["alligators"].min).to eq 2
241
+ end
242
+ end
243
+
244
+ describe "with an array where all elements should match by type and there is only a match:type on the parent element" do
245
+ let(:expected) do
246
+ {
247
+ 'alligators' => [{'name' => 'Mary'}]
248
+ }
242
249
  end
243
250
 
244
- describe "with an array where all elements should match by type nested inside another array where all elements should match by type" do
245
- let(:expected) do
246
- {
251
+ let(:matching_rules) do
252
+ {
253
+ "$.body.alligators" => { 'min' => 2, 'match' => 'type' },
254
+ }
255
+ end
247
256
 
248
- 'alligators' => [
249
- {
250
- 'name' => 'Mary',
251
- 'children' => [
252
- 'age' => 9
253
- ]
254
- }
255
- ]
257
+ it "creates a Pact::ArrayLike at the appropriate path" do
258
+ expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
259
+ expect(subject["alligators"].contents).to eq 'name' => 'Mary'
260
+ expect(subject["alligators"].min).to eq 2
261
+ end
262
+ end
256
263
 
257
- }
258
- end
264
+ describe "with an array where all elements should match by type nested inside another array where all elements should match by type" do
265
+ let(:expected) do
266
+ {
259
267
 
260
- let(:matching_rules) do
261
- {
262
- "$.body.alligators" => { 'min' => 2 },
263
- "$.body.alligators[*].*" => { 'match' => 'type'},
264
- "$.body.alligators[*].children" => { 'min' => 1 },
265
- "$.body.alligators[*].children[*].*" => { 'match' => 'type'}
266
- }
267
- end
268
+ 'alligators' => [
269
+ {
270
+ 'name' => 'Mary',
271
+ 'children' => [
272
+ 'age' => 9
273
+ ]
274
+ }
275
+ ]
268
276
 
269
- it "creates a Pact::ArrayLike at the appropriate path" do
270
- expect(subject["alligators"].contents['children']).to be_instance_of(Pact::ArrayLike)
271
- expect(subject["alligators"].contents['children'].contents).to eq 'age' => 9
272
- expect(subject["alligators"].contents['children'].min).to eq 1
273
- end
277
+ }
274
278
  end
275
279
 
276
- describe "with an example array with more than one item" do
277
- before do
278
- allow(Pact.configuration.error_stream).to receive(:puts)
279
- end
280
+ let(:matching_rules) do
281
+ {
282
+ "$.body.alligators" => { 'min' => 2 },
283
+ "$.body.alligators[*].*" => { 'match' => 'type'},
284
+ "$.body.alligators[*].children" => { 'min' => 1 },
285
+ "$.body.alligators[*].children[*].*" => { 'match' => 'type'}
286
+ }
287
+ end
280
288
 
281
- let(:expected) do
282
- {
289
+ it "creates a Pact::ArrayLike at the appropriate path" do
290
+ expect(subject["alligators"].contents['children']).to be_instance_of(Pact::ArrayLike)
291
+ expect(subject["alligators"].contents['children'].contents).to eq 'age' => 9
292
+ expect(subject["alligators"].contents['children'].min).to eq 1
293
+ end
294
+ end
283
295
 
284
- 'alligators' => [
285
- {'name' => 'Mary'},
286
- {'name' => 'Joe'}
287
- ]
296
+ describe "with an example array with more than one item" do
297
+ before do
298
+ allow(Pact.configuration.error_stream).to receive(:puts)
299
+ end
288
300
 
289
- }
290
- end
301
+ let(:expected) do
302
+ {
291
303
 
292
- let(:matching_rules) do
293
- {
294
- "$.body.alligators" => { 'min' => 2 },
295
- "$.body.alligators[*].*" => { 'match' => 'type'}
296
- }
297
- end
304
+ 'alligators' => [
305
+ {'name' => 'Mary'},
306
+ {'name' => 'Joe'}
307
+ ]
298
308
 
299
- it "warns that the other items will be ignored" do
300
- expect(Pact.configuration.error_stream).to receive(:puts).with(/WARN: Only the first item/)
301
- subject
302
- end
309
+ }
310
+ end
311
+
312
+ let(:matching_rules) do
313
+ {
314
+ "$.body.alligators" => { 'min' => 2 },
315
+ "$.body.alligators[*].*" => { 'match' => 'type'}
316
+ }
317
+ end
318
+
319
+ it "warns that the other items will be ignored" do
320
+ expect(Pact.configuration.error_stream).to receive(:puts).with(/WARN: Only the first item/)
321
+ subject
303
322
  end
304
323
  end
305
324
 
325
+
306
326
  describe "using bracket notation for a Hash" do
307
327
  let(:expected) do
308
328
  {
@@ -94,7 +94,7 @@ module Pact
94
94
  end
95
95
 
96
96
  it "it logs the rules it has ignored" do
97
- expect($stderr).to receive(:puts).with(/ignored.*matchingrule/)
97
+ expect($stderr).to receive(:puts).once.with(/ignored.*matchingrule/)
98
98
  subject
99
99
  end
100
100
 
@@ -105,6 +105,61 @@ module Pact
105
105
  end
106
106
  end
107
107
 
108
+ describe "when a Pact.like is nested inside a Pact.each_like which is nested inside a Pact.like" do
109
+ let(:original_definition) do
110
+ Pact.like('foos' => Pact.each_like(Pact.like('name' => "foo1")))
111
+ end
112
+
113
+ let(:expected) do
114
+ Pact::Reification.from_term(original_definition)
115
+ end
116
+
117
+ let(:matching_rules) do
118
+ Extract.call(original_definition)
119
+ end
120
+
121
+ it "creates a Pact::SomethingLike containing a Pact::ArrayLike containing a Pact::SomethingLike" do
122
+ expect(subject.to_hash).to eq original_definition.to_hash
123
+ end
124
+ end
125
+
126
+ describe "when a Pact.array_like is the top level object" do
127
+ let(:original_definition) do
128
+ Pact.each_like('foos')
129
+ end
130
+
131
+ let(:expected) do
132
+ Pact::Reification.from_term(original_definition)
133
+ end
134
+
135
+ let(:matching_rules) do
136
+ Extract.call(original_definition)
137
+ end
138
+
139
+ it "creates a Pact::ArrayLike" do
140
+ expect(subject.to_hash).to eq original_definition.to_hash
141
+ end
142
+ end
143
+
144
+ describe "when a Pact.like containing an array is the top level object" do
145
+ let(:original_definition) do
146
+ Pact.like(['foos'])
147
+ end
148
+
149
+ let(:expected) do
150
+ Pact::Reification.from_term(original_definition).tap { |it| puts it }
151
+ end
152
+
153
+ let(:matching_rules) do
154
+ Extract.call(original_definition).tap { |it| puts it }
155
+ end
156
+
157
+ it "creates a Pact::SomethingLike" do
158
+ expect(subject).to be_a(Pact::SomethingLike)
159
+ expect(subject.to_hash).to eq original_definition.to_hash
160
+ end
161
+ end
162
+
108
163
  describe "regular expressions" do
109
164
  describe "in a hash" do
110
165
  before do
@@ -172,158 +227,178 @@ module Pact
172
227
  end
173
228
  end
174
229
 
175
- describe "with an array where all elements should match by type and the rule is specified on the parent element and there is no min specified" do
230
+ describe "with an ArrayLike containing a Term" do
176
231
  let(:expected) do
177
- {
178
- 'alligators' => [{'name' => 'Mary'}]
179
- }
232
+ ["foo"]
180
233
  end
181
234
 
182
235
  let(:matching_rules) do
183
236
  {
184
- "$.alligators" => {
185
- "matchers" => [{ 'match' => 'type' }]
186
- }
237
+ "$" => {"matchers" => [{"min" => 1}]},
238
+ "$[*].*" => {"matchers" => [{"match" => "type"}]},
239
+ "$[*]" => {"matchers" => [{"match" => "regex", "regex"=>"f"}]}
187
240
  }
188
241
  end
189
242
 
190
- it "creates a Pact::SomethingLike at the appropriate path" do
191
- expect(subject["alligators"]).to be_instance_of(Pact::SomethingLike)
192
- expect(subject["alligators"].contents).to eq ['name' => 'Mary']
243
+ it "it creates an ArrayLike with a Pact::Term as the contents" do
244
+ expect(subject).to be_a(Pact::ArrayLike)
245
+ expect(subject.contents).to be_a(Pact::Term)
193
246
  end
194
247
  end
248
+ end
195
249
 
196
- describe "with an array where all elements should match by type and the rule is specified on the child elements" do
197
- let(:expected) do
198
- {
199
- 'alligators' => [{'name' => 'Mary'}]
200
- }
201
- end
250
+ describe "with an array where all elements should match by type and the rule is specified on the parent element and there is no min specified" do
251
+ let(:expected) do
252
+ {
253
+ 'alligators' => [{'name' => 'Mary'}]
254
+ }
255
+ end
202
256
 
203
- let(:matching_rules) do
204
- {
205
- "$.alligators" => {
206
- "matchers" => [{ 'min' => 2, 'match' => 'type' }]
207
- },
208
- "$.alligators[*].*" => {
209
- "matchers" => [{ 'match' => 'type'}]
210
- }
257
+ let(:matching_rules) do
258
+ {
259
+ "$.alligators" => {
260
+ "matchers" => [{ 'match' => 'type' }]
211
261
  }
212
- end
213
- it "creates a Pact::ArrayLike at the appropriate path" do
214
- expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
215
- expect(subject["alligators"].contents).to eq 'name' => 'Mary'
216
- expect(subject["alligators"].min).to eq 2
217
- end
262
+ }
218
263
  end
219
264
 
220
- describe "with an array where all elements should match by type and the rule is specified on both the parent element and the child elements" do
221
- let(:expected) do
222
- {
223
- 'alligators' => [{'name' => 'Mary'}]
224
- }
225
- end
265
+ it "creates a Pact::SomethingLike at the appropriate path" do
266
+ expect(subject["alligators"]).to be_instance_of(Pact::SomethingLike)
267
+ expect(subject["alligators"].contents).to eq ['name' => 'Mary']
268
+ end
269
+ end
226
270
 
227
- let(:matching_rules) do
228
- {
229
- "$.alligators" => {
230
- "matchers" => [{ 'min' => 2, 'match' => 'type' }]
231
- },
232
- "$.alligators[*].*" => {
233
- "matchers" => [{ 'match' => 'type' }]
234
- }
271
+ describe "with an array where all elements should match by type and the rule is specified on the child elements" do
272
+ let(:expected) do
273
+ {
274
+ 'alligators' => [{'name' => 'Mary'}]
275
+ }
276
+ end
277
+
278
+ let(:matching_rules) do
279
+ {
280
+ "$.alligators" => {
281
+ "matchers" => [{ 'min' => 2}]
282
+ },
283
+ "$.alligators[*].*" => {
284
+ "matchers" => [{ 'match' => 'type'}]
235
285
  }
236
- end
286
+ }
287
+ end
288
+ it "creates a Pact::ArrayLike at the appropriate path" do
289
+ expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
290
+ expect(subject["alligators"].contents).to eq 'name' => 'Mary'
291
+ expect(subject["alligators"].min).to eq 2
292
+ end
293
+ end
237
294
 
238
- it "creates a Pact::ArrayLike at the appropriate path" do
239
- expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
240
- expect(subject["alligators"].contents).to eq 'name' => 'Mary'
241
- expect(subject["alligators"].min).to eq 2
242
- end
295
+ describe "with an array where all elements should match by type and the rule is specified on both the parent element and the child elements" do
296
+ let(:expected) do
297
+ {
298
+ 'alligators' => [{'name' => 'Mary'}]
299
+ }
243
300
  end
244
301
 
245
- describe "with an array where all elements should match by type and there is only a match:type on the parent element" do
246
- let(:expected) do
247
- {
248
- 'alligators' => [{'name' => 'Mary'}]
302
+ let(:matching_rules) do
303
+ {
304
+ "$.alligators" => {
305
+ "matchers" => [{ 'min' => 2, 'match' => 'type' }]
306
+ },
307
+ "$.alligators[*].*" => {
308
+ "matchers" => [{ 'match' => 'type' }]
249
309
  }
250
- end
310
+ }
311
+ end
251
312
 
252
- let(:matching_rules) do
253
- {
254
- "$.alligators" => { 'matchers' => [{'min' => 2, 'match' => 'type'}] },
255
- }
256
- end
313
+ it "creates a Pact::ArrayLike at the appropriate path" do
314
+ expect(subject["alligators"]).to be_instance_of(Pact::SomethingLike)
315
+ expect(subject["alligators"].contents).to be_instance_of(Pact::ArrayLike)
316
+ expect(subject["alligators"].contents.contents).to eq 'name' => 'Mary'
317
+ expect(subject["alligators"].contents.min).to eq 2
318
+ end
319
+ end
257
320
 
258
- it "creates a Pact::ArrayLike at the appropriate path" do
259
- expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
260
- expect(subject["alligators"].contents).to eq 'name' => 'Mary'
261
- expect(subject["alligators"].min).to eq 2
262
- end
321
+ describe "with an array where all elements should match by type and there is only a match:type on the parent element" do
322
+ let(:expected) do
323
+ {
324
+ 'alligators' => [{'name' => 'Mary'}]
325
+ }
263
326
  end
264
327
 
265
- describe "with an array where all elements should match by type nested inside another array where all elements should match by type" do
266
- let(:expected) do
267
- {
328
+ let(:matching_rules) do
329
+ {
330
+ "$.alligators" => { 'matchers' => [{'min' => 2, 'match' => 'type'}] },
331
+ }
332
+ end
268
333
 
269
- 'alligators' => [
270
- {
271
- 'name' => 'Mary',
272
- 'children' => [
273
- 'age' => 9
274
- ]
275
- }
276
- ]
334
+ it "creates a Pact::ArrayLike at the appropriate path" do
335
+ expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
336
+ expect(subject["alligators"].contents).to eq 'name' => 'Mary'
337
+ expect(subject["alligators"].min).to eq 2
338
+ end
339
+ end
277
340
 
278
- }
279
- end
341
+ describe "with an array where all elements should match by type nested inside another array where all elements should match by type" do
342
+ let(:expected) do
343
+ {
280
344
 
281
- let(:matching_rules) do
282
- {
283
- "$.alligators" => { "matchers" => [{ 'min' => 2, 'match' => 'type' }] },
284
- "$.alligators[*].children" => { "matchers" => [{ 'min' => 1, 'match' => 'type' }]},
285
- }
286
- end
345
+ 'alligators' => [
346
+ {
347
+ 'name' => 'Mary',
348
+ 'children' => [
349
+ 'age' => 9
350
+ ]
351
+ }
352
+ ]
287
353
 
288
- it "creates a Pact::ArrayLike at the appropriate path" do
289
- expect(subject["alligators"].contents['children']).to be_instance_of(Pact::ArrayLike)
290
- expect(subject["alligators"].contents['children'].contents).to eq 'age' => 9
291
- expect(subject["alligators"].contents['children'].min).to eq 1
292
- end
354
+ }
293
355
  end
294
356
 
295
- describe "with an example array with more than one item" do
296
- before do
297
- allow($stderr).to receive(:puts)
298
- end
357
+ let(:matching_rules) do
358
+ {
359
+ "$.alligators" => { "matchers" => [{ 'min' => 2, 'match' => 'type' }] },
360
+ "$.alligators[*].children" => { "matchers" => [{ 'min' => 1, 'match' => 'type' }]},
361
+ }
362
+ end
299
363
 
300
- let(:expected) do
301
- {
364
+ it "creates a Pact::ArrayLike at the appropriate path" do
365
+ expect(subject["alligators"].contents['children']).to be_instance_of(Pact::ArrayLike)
366
+ expect(subject["alligators"].contents['children'].contents).to eq 'age' => 9
367
+ expect(subject["alligators"].contents['children'].min).to eq 1
368
+ end
369
+ end
302
370
 
303
- 'alligators' => [
304
- {'name' => 'Mary'},
305
- {'name' => 'Joe'}
306
- ]
371
+ describe "with an example array with more than one item" do
372
+ before do
373
+ allow($stderr).to receive(:puts)
374
+ end
307
375
 
308
- }
309
- end
376
+ let(:expected) do
377
+ {
310
378
 
311
- let(:matching_rules) do
312
- {
313
- "$.alligators" => { "matchers" => [{'min' => 2, 'match' => 'type'}] }
314
- }
315
- end
379
+ 'alligators' => [
380
+ {'name' => 'Mary'},
381
+ {'name' => 'Joe'}
382
+ ]
316
383
 
317
- it "doesn't warn about the min size being ignored" do
318
- expect(Pact.configuration.error_stream).to receive(:puts).once
319
- subject
320
- end
384
+ }
385
+ end
321
386
 
322
- it "warns that the other items will be ignored" do
323
- allow(Pact.configuration.error_stream).to receive(:puts)
324
- expect(Pact.configuration.error_stream).to receive(:puts).with(/WARN: Only the first item/)
325
- subject
326
- end
387
+ let(:matching_rules) do
388
+ {
389
+ "$.alligators" => { "matchers" => [{'min' => 2, 'match' => 'type'}] }
390
+ }
391
+ end
392
+
393
+ it "doesn't warn about the min size being ignored" do
394
+ expect(Pact.configuration.error_stream).to receive(:puts).once
395
+ subject
396
+ end
397
+
398
+ it "warns that the other items will be ignored" do
399
+ allow(Pact.configuration.error_stream).to receive(:puts)
400
+ expect(Pact.configuration.error_stream).to receive(:puts).with(/WARN: Only the first item/)
401
+ subject
327
402
  end
328
403
  end
329
404
 
@@ -380,6 +455,7 @@ module Pact
380
455
  expect(subject['@name']).to be_instance_of(Pact::SomethingLike)
381
456
  end
382
457
  end
458
+
383
459
  end
384
460
  end
385
461
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-08-09 00:00:00.000000000 Z
15
+ date: 2018-08-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp