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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/pact/matching_rules/v3/merge.rb +17 -10
- data/lib/pact/support/version.rb +1 -1
- data/spec/lib/pact/matching_rules/merge_spec.rb +126 -106
- data/spec/lib/pact/matching_rules/v3/merge_spec.rb +192 -116
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c575784ba0803bdeccb12e271ffdec723771497
|
4
|
+
data.tar.gz: a81a629772d07d9ba46da3be40d461a4906c667c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af8f2fd481a2b5886b6369883d1f4ea696406d16cfc55024958116cc2b170548e4271a1a37125ceddba76be643bf2a8c58ac7d4e5fd17f2fc887002e085a360d
|
7
|
+
data.tar.gz: 31127041531129db0c31928c8c17bedf54566133bf886725e6db5285a9676c19185767f5f86ff784a7a5a1cfdcf059564e5eae08a5b693c63ce77d5d247e8bc5
|
data/CHANGELOG.md
CHANGED
@@ -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(
|
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]
|
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]
|
54
|
-
min = @matching_rules[path]
|
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 &&
|
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(
|
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(
|
99
|
+
Pact::SomethingLike.new(object)
|
93
100
|
end
|
94
101
|
|
95
102
|
def handle_regex object, path, rules
|
data/lib/pact/support/version.rb
CHANGED
@@ -160,149 +160,169 @@ module Pact
|
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
-
describe "with an
|
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
|
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::
|
177
|
-
expect(subject
|
178
|
-
expect(subject
|
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
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
end
|
190
|
+
let(:matching_rules) do
|
191
|
+
{
|
192
|
+
"$.body.alligators" => { 'match' => 'type' }
|
193
|
+
}
|
194
|
+
end
|
195
195
|
|
196
|
-
|
197
|
-
|
198
|
-
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
209
|
+
let(:matching_rules) do
|
210
|
+
{
|
211
|
+
"$.body.alligators" => { 'min' => 2 },
|
212
|
+
"$.body.alligators[*].*" => { 'match' => 'type'}
|
213
|
+
}
|
214
|
+
end
|
216
215
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
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
|
-
|
232
|
-
|
233
|
-
|
234
|
-
}
|
235
|
-
|
230
|
+
let(:matching_rules) do
|
231
|
+
{
|
232
|
+
"$.body.alligators" => { 'min' => 2, 'match' => 'type' },
|
233
|
+
"$.body.alligators[*].*" => { 'match' => 'type'}
|
234
|
+
}
|
235
|
+
end
|
236
236
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
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
|
-
|
245
|
-
|
246
|
-
{
|
251
|
+
let(:matching_rules) do
|
252
|
+
{
|
253
|
+
"$.body.alligators" => { 'min' => 2, 'match' => 'type' },
|
254
|
+
}
|
255
|
+
end
|
247
256
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
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
|
-
|
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
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
+
'alligators' => [
|
269
|
+
{
|
270
|
+
'name' => 'Mary',
|
271
|
+
'children' => [
|
272
|
+
'age' => 9
|
273
|
+
]
|
274
|
+
}
|
275
|
+
]
|
268
276
|
|
269
|
-
|
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
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
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
|
-
|
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
|
-
|
285
|
-
|
286
|
-
|
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
|
-
|
301
|
+
let(:expected) do
|
302
|
+
{
|
291
303
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
}
|
297
|
-
end
|
304
|
+
'alligators' => [
|
305
|
+
{'name' => 'Mary'},
|
306
|
+
{'name' => 'Joe'}
|
307
|
+
]
|
298
308
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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
|
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
|
-
"
|
185
|
-
|
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::
|
191
|
-
expect(subject
|
192
|
-
expect(subject
|
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
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
},
|
208
|
-
"$.alligators[*].*" => {
|
209
|
-
"matchers" => [{ 'match' => 'type'}]
|
210
|
-
}
|
257
|
+
let(:matching_rules) do
|
258
|
+
{
|
259
|
+
"$.alligators" => {
|
260
|
+
"matchers" => [{ 'match' => 'type' }]
|
211
261
|
}
|
212
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
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
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
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
|
-
|
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
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
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
|
-
|
246
|
-
|
247
|
-
{
|
248
|
-
|
302
|
+
let(:matching_rules) do
|
303
|
+
{
|
304
|
+
"$.alligators" => {
|
305
|
+
"matchers" => [{ 'min' => 2, 'match' => 'type' }]
|
306
|
+
},
|
307
|
+
"$.alligators[*].*" => {
|
308
|
+
"matchers" => [{ 'match' => 'type' }]
|
249
309
|
}
|
250
|
-
|
310
|
+
}
|
311
|
+
end
|
251
312
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
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
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
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
|
-
|
266
|
-
|
267
|
-
{
|
328
|
+
let(:matching_rules) do
|
329
|
+
{
|
330
|
+
"$.alligators" => { 'matchers' => [{'min' => 2, 'match' => 'type'}] },
|
331
|
+
}
|
332
|
+
end
|
268
333
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
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
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
345
|
+
'alligators' => [
|
346
|
+
{
|
347
|
+
'name' => 'Mary',
|
348
|
+
'children' => [
|
349
|
+
'age' => 9
|
350
|
+
]
|
351
|
+
}
|
352
|
+
]
|
287
353
|
|
288
|
-
|
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
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
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
|
-
|
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
|
-
|
304
|
-
|
305
|
-
|
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
|
-
|
376
|
+
let(:expected) do
|
377
|
+
{
|
310
378
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
end
|
379
|
+
'alligators' => [
|
380
|
+
{'name' => 'Mary'},
|
381
|
+
{'name' => 'Joe'}
|
382
|
+
]
|
316
383
|
|
317
|
-
|
318
|
-
|
319
|
-
subject
|
320
|
-
end
|
384
|
+
}
|
385
|
+
end
|
321
386
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
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.
|
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-
|
15
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: randexp
|