pact-support 1.9.0 → 1.15.0

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.
Files changed (112) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +124 -0
  3. data/lib/pact/configuration.rb +7 -0
  4. data/lib/pact/consumer_contract/consumer_contract.rb +12 -1
  5. data/lib/pact/consumer_contract/http_consumer_contract_parser.rb +1 -1
  6. data/lib/pact/consumer_contract/interaction.rb +5 -1
  7. data/lib/pact/consumer_contract/interaction_v2_parser.rb +9 -1
  8. data/lib/pact/consumer_contract/interaction_v3_parser.rb +22 -3
  9. data/lib/pact/consumer_contract/pact_file.rb +32 -1
  10. data/lib/pact/matchers/matchers.rb +33 -13
  11. data/lib/pact/matching_rules/v3/merge.rb +4 -2
  12. data/lib/pact/shared/multipart_form_differ.rb +2 -0
  13. data/lib/pact/support/version.rb +1 -1
  14. data/lib/pact/term.rb +0 -1
  15. metadata +5 -228
  16. data/.gitignore +0 -32
  17. data/.rspec +0 -3
  18. data/.travis.yml +0 -29
  19. data/Appraisals +0 -7
  20. data/Gemfile +0 -4
  21. data/RELEASING.md +0 -5
  22. data/Rakefile +0 -4
  23. data/gemfiles/default.gemfile +0 -5
  24. data/gemfiles/ruby_under_22.gemfile +0 -8
  25. data/pact-support.gemspec +0 -39
  26. data/script/release.sh +0 -9
  27. data/script/update-pact-specification-v2 +0 -9
  28. data/spec/fixtures/interaction-with-matching-rules.json +0 -27
  29. data/spec/fixtures/multipart-form-diff.txt +0 -9
  30. data/spec/fixtures/not-a-pact.json +0 -3
  31. data/spec/fixtures/pact-http-v2.json +0 -36
  32. data/spec/fixtures/pact-http-v3.json +0 -36
  33. data/spec/integration/matching_rules_extract_and_merge_spec.rb +0 -127
  34. data/spec/lib/pact/array_like_spec.rb +0 -37
  35. data/spec/lib/pact/configuration_spec.rb +0 -61
  36. data/spec/lib/pact/consumer/request_spec.rb +0 -25
  37. data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
  38. data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -142
  39. data/spec/lib/pact/consumer_contract/file_name_spec.rb +0 -24
  40. data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
  41. data/spec/lib/pact/consumer_contract/http_consumer_contract_parser_spec.rb +0 -25
  42. data/spec/lib/pact/consumer_contract/interaction_parser_spec.rb +0 -62
  43. data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -121
  44. data/spec/lib/pact/consumer_contract/interaction_v2_parser_spec.rb +0 -54
  45. data/spec/lib/pact/consumer_contract/interaction_v3_parser_spec.rb +0 -48
  46. data/spec/lib/pact/consumer_contract/pact_file_spec.rb +0 -204
  47. data/spec/lib/pact/consumer_contract/query_hash_spec.rb +0 -154
  48. data/spec/lib/pact/consumer_contract/query_string_spec.rb +0 -131
  49. data/spec/lib/pact/consumer_contract/request_spec.rb +0 -486
  50. data/spec/lib/pact/consumer_contract/response_spec.rb +0 -82
  51. data/spec/lib/pact/helpers_spec.rb +0 -143
  52. data/spec/lib/pact/matchers/differ_spec.rb +0 -215
  53. data/spec/lib/pact/matchers/difference_spec.rb +0 -22
  54. data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
  55. data/spec/lib/pact/matchers/extract_diff_messages_spec.rb +0 -78
  56. data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
  57. data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -121
  58. data/spec/lib/pact/matchers/matchers_array_like_spec.rb +0 -222
  59. data/spec/lib/pact/matchers/matchers_messages_hash_and_array_spec.rb +0 -146
  60. data/spec/lib/pact/matchers/matchers_messages_mismatched_value_spec.rb +0 -71
  61. data/spec/lib/pact/matchers/matchers_messages_regexp_spec.rb +0 -103
  62. data/spec/lib/pact/matchers/matchers_spec.rb +0 -521
  63. data/spec/lib/pact/matchers/multipart_form_diff_formatter_spec.rb +0 -36
  64. data/spec/lib/pact/matchers/no_diff_at_index_spec.rb +0 -15
  65. data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
  66. data/spec/lib/pact/matchers/type_difference_spec.rb +0 -36
  67. data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
  68. data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
  69. data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -235
  70. data/spec/lib/pact/matching_rules/extract_spec.rb +0 -216
  71. data/spec/lib/pact/matching_rules/merge_spec.rb +0 -436
  72. data/spec/lib/pact/matching_rules/v3/extract_spec.rb +0 -238
  73. data/spec/lib/pact/matching_rules/v3/merge_spec.rb +0 -485
  74. data/spec/lib/pact/matching_rules_spec.rb +0 -82
  75. data/spec/lib/pact/reification_spec.rb +0 -172
  76. data/spec/lib/pact/shared/dsl_spec.rb +0 -100
  77. data/spec/lib/pact/shared/form_differ_spec.rb +0 -71
  78. data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
  79. data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
  80. data/spec/lib/pact/shared/multipart_form_differ_spec.rb +0 -39
  81. data/spec/lib/pact/shared/request_spec.rb +0 -235
  82. data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
  83. data/spec/lib/pact/something_like_spec.rb +0 -23
  84. data/spec/lib/pact/support_spec.rb +0 -9
  85. data/spec/lib/pact/symbolize_keys_spec.rb +0 -15
  86. data/spec/lib/pact/term_spec.rb +0 -89
  87. data/spec/pact_specification/compliance-2.0.rb +0 -66
  88. data/spec/spec_helper.rb +0 -18
  89. data/spec/support/a_consumer-a_producer.json +0 -32
  90. data/spec/support/a_consumer-a_provider.json +0 -32
  91. data/spec/support/active_support_if_configured.rb +0 -6
  92. data/spec/support/case-insensitive-response-header-matching.json +0 -21
  93. data/spec/support/consumer_contract_template.json +0 -24
  94. data/spec/support/dsl_spec_support.rb +0 -7
  95. data/spec/support/factories.rb +0 -87
  96. data/spec/support/generated_index.md +0 -4
  97. data/spec/support/generated_markdown.md +0 -55
  98. data/spec/support/interaction_view_model.json +0 -63
  99. data/spec/support/interaction_view_model_with_terms.json +0 -50
  100. data/spec/support/markdown_pact.json +0 -48
  101. data/spec/support/missing_provider_states_output.txt +0 -25
  102. data/spec/support/options.json +0 -21
  103. data/spec/support/ruby_version_helpers.rb +0 -23
  104. data/spec/support/shared_examples_for_request.rb +0 -132
  105. data/spec/support/spec_support.rb +0 -29
  106. data/spec/support/stubbing.json +0 -22
  107. data/spec/support/term.json +0 -48
  108. data/spec/support/test_app_fail.json +0 -61
  109. data/spec/support/test_app_pass.json +0 -38
  110. data/spec/support/test_app_with_right_content_type_differ.json +0 -23
  111. data/tasks/release.rake +0 -5
  112. data/tasks/spec.rake +0 -14
@@ -1,436 +0,0 @@
1
- require 'pact/matching_rules/merge'
2
-
3
- module Pact
4
- module MatchingRules
5
- describe Merge do
6
-
7
- subject { Merge.(expected, matching_rules, "$.body") }
8
-
9
- before do
10
- allow($stderr).to receive(:puts) do | message |
11
- raise "Was not expecting stderr to receive #{message.inspect} in this spec. This may be because of a missed call to log_used_rule in Merge."
12
- end
13
- end
14
-
15
- describe "no recognised rules" do
16
- before do
17
- allow($stderr).to receive(:puts)
18
- end
19
-
20
- let(:expected) do
21
- {
22
- "_links" => {
23
- "self" => {
24
- "href" => "http://localhost:1234/thing"
25
- }
26
- }
27
- }
28
- end
29
-
30
- let(:matching_rules) do
31
- {
32
- "$.body._links.self.href" => {"type" => "unknown" }
33
- }
34
- end
35
-
36
- it "returns the object at that path unaltered" do
37
- expect(subject["_links"]["self"]["href"]).to eq "http://localhost:1234/thing"
38
- end
39
-
40
- it "it logs the rules it has ignored" do
41
- expect($stderr).to receive(:puts) do | message |
42
- expect(message).to include("WARN")
43
- expect(message).to include("type")
44
- expect(message).to include("unknown")
45
- expect(message).to include("$['body']")
46
- end
47
- subject
48
- end
49
-
50
- end
51
-
52
- describe "with nil rules" do
53
- let(:expected) do
54
- {
55
- "_links" => {
56
- "self" => {
57
- "href" => "http://localhost:1234/thing"
58
- }
59
- }
60
- }
61
- end
62
-
63
- let(:matching_rules) { nil }
64
-
65
- it "returns the example unaltered" do
66
- expect(subject["_links"]["self"]["href"]).to eq "http://localhost:1234/thing"
67
- end
68
-
69
- end
70
-
71
- describe "type based matching" do
72
- before do
73
- allow($stderr).to receive(:puts).and_call_original
74
- end
75
-
76
- let(:expected) do
77
- {
78
- "name" => "Mary"
79
- }
80
- end
81
-
82
- let(:matching_rules) do
83
- {
84
- "$.body.name" => { "match" => "type", "ignored" => "matchingrule" }
85
- }
86
- end
87
-
88
- it "creates a SomethingLike at the appropriate path" do
89
- expect(subject['name']).to be_instance_of(Pact::SomethingLike)
90
- end
91
-
92
- it "it logs the rules it has ignored" do
93
- expect($stderr).to receive(:puts).once.with(/ignored.*matchingrule/)
94
- subject
95
- end
96
-
97
- end
98
-
99
- describe "regular expressions" do
100
-
101
- describe "in a hash" do
102
- before do
103
- allow($stderr).to receive(:puts)
104
- end
105
-
106
- let(:expected) do
107
- {
108
- "_links" => {
109
- "self" => {
110
- "href" => "http://localhost:1234/thing"
111
- }
112
- }
113
- }
114
- end
115
-
116
- let(:matching_rules) do
117
- {
118
- "$.body._links.self.href" => { "regex" => "http:\\/\\/.*\\/thing", "match" => "regex", "ignored" => "somerule" }
119
- }
120
- end
121
-
122
- it "creates a Pact::Term at the appropriate path" do
123
- expect(subject["_links"]["self"]["href"]).to be_instance_of(Pact::Term)
124
- expect(subject["_links"]["self"]["href"].generate).to eq "http://localhost:1234/thing"
125
- expect(subject["_links"]["self"]["href"].matcher.inspect).to eq "/http:\\/\\/.*\\/thing/"
126
- end
127
-
128
- it "it logs the rules it has ignored" do
129
- expect($stderr).to receive(:puts) do | message |
130
- expect(message).to match /ignored.*"somerule"/
131
- expect(message).to_not match /regex/
132
- expect(message).to_not match /"match"/
133
- end
134
- subject
135
- end
136
- end
137
-
138
- describe "with an array" do
139
-
140
- let(:expected) do
141
- {
142
- "_links" => {
143
- "self" => [{
144
- "href" => "http://localhost:1234/thing"
145
- }]
146
- }
147
- }
148
- end
149
-
150
- let(:matching_rules) do
151
- {
152
- "$.body._links.self[0].href" => { "regex" => "http:\\/\\/.*\\/thing" }
153
- }
154
- end
155
-
156
- it "creates a Pact::Term at the appropriate path" do
157
- expect(subject["_links"]["self"][0]["href"]).to be_instance_of(Pact::Term)
158
- expect(subject["_links"]["self"][0]["href"].generate).to eq "http://localhost:1234/thing"
159
- expect(subject["_links"]["self"][0]["href"].matcher.inspect).to eq "/http:\\/\\/.*\\/thing/"
160
- end
161
- end
162
-
163
- describe "with an ArrayLike containing a Term" do
164
- let(:expected) do
165
- ["foo"]
166
- end
167
-
168
- let(:matching_rules) do
169
- {
170
- "$.body" => {"min" => 1},
171
- "$.body[*].*" => {"match" => "type"},
172
- "$.body[*]" => {"match" => "regex", "regex"=>"f"}
173
- }
174
- end
175
-
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
- end
180
- end
181
- end
182
-
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
189
-
190
- let(:matching_rules) do
191
- {
192
- "$.body.alligators" => { 'match' => 'type' }
193
- }
194
- end
195
-
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']
199
- end
200
- end
201
-
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
208
-
209
- let(:matching_rules) do
210
- {
211
- "$.body.alligators" => { 'min' => 2 },
212
- "$.body.alligators[*].*" => { 'match' => 'type'}
213
- }
214
- end
215
-
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
220
- end
221
- end
222
-
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
229
-
230
- let(:matching_rules) do
231
- {
232
- "$.body.alligators" => { 'min' => 2, 'match' => 'type' },
233
- "$.body.alligators[*].*" => { 'match' => 'type'}
234
- }
235
- end
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
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
- }
249
- end
250
-
251
- let(:matching_rules) do
252
- {
253
- "$.body.alligators" => { 'min' => 2, 'match' => 'type' },
254
- }
255
- end
256
-
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
263
-
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
- {
267
-
268
- 'alligators' => [
269
- {
270
- 'name' => 'Mary',
271
- 'children' => [
272
- 'age' => 9
273
- ]
274
- }
275
- ]
276
-
277
- }
278
- end
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
288
-
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
295
-
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
300
-
301
- let(:expected) do
302
- {
303
-
304
- 'alligators' => [
305
- {'name' => 'Mary'},
306
- {'name' => 'Joe'}
307
- ]
308
-
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
322
- end
323
- end
324
-
325
-
326
- describe "using bracket notation for a Hash" do
327
- let(:expected) do
328
- {
329
- "name" => "Mary"
330
- }
331
- end
332
-
333
- let(:matching_rules) do
334
- {
335
- "$.body['name']" => { "match" => "type" }
336
- }
337
- end
338
-
339
- it "applies the rule" do
340
- expect(subject['name']).to be_instance_of(Pact::SomethingLike)
341
- end
342
- end
343
-
344
- describe "with a dot in the path" do
345
- let(:expected) do
346
- {
347
- "first.name" => "Mary"
348
- }
349
- end
350
-
351
- let(:matching_rules) do
352
- {
353
- "$.body['first.name']" => { "match" => "type" }
354
- }
355
- end
356
-
357
- it "applies the rule" do
358
- expect(subject['first.name']).to be_instance_of(Pact::SomethingLike)
359
- end
360
- end
361
-
362
- describe "with an @ in the path" do
363
- let(:expected) do
364
- {
365
- "@name" => "Mary"
366
- }
367
- end
368
-
369
- let(:matching_rules) do
370
- {
371
- "$.body['@name']" => { "match" => "type" }
372
- }
373
- end
374
-
375
- it "applies the rule" do
376
- expect(subject['@name']).to be_instance_of(Pact::SomethingLike)
377
- end
378
- end
379
-
380
- describe "when a Pact.like is nested inside a Pact.each_like which is nested inside a Pact.like" do
381
- let(:original_definition) do
382
- Pact.like('foos' => Pact.each_like(Pact.like('name' => "foo1")))
383
- end
384
-
385
- let(:expected) do
386
- Pact::Reification.from_term(original_definition)
387
- end
388
-
389
- let(:matching_rules) do
390
- Extract.call(body: original_definition)
391
- end
392
-
393
- it "creates a Pact::SomethingLike containing a Pact::ArrayLike containing a Pact::SomethingLike" do
394
- expect(subject.to_hash).to eq original_definition.to_hash
395
- end
396
- end
397
-
398
- describe "when a Pact.array_like is the top level object" do
399
- let(:original_definition) do
400
- Pact.each_like('foos')
401
- end
402
-
403
- let(:expected) do
404
- Pact::Reification.from_term(original_definition)
405
- end
406
-
407
- let(:matching_rules) do
408
- Extract.call(body: original_definition)
409
- end
410
-
411
- it "creates a Pact::ArrayLike" do
412
- expect(subject.to_hash).to eq original_definition.to_hash
413
- end
414
- end
415
-
416
- describe "when a Pact.like containing an array is the top level object" do
417
- let(:original_definition) do
418
- Pact.like(['foos'])
419
- end
420
-
421
- let(:expected) do
422
- Pact::Reification.from_term(original_definition)
423
- end
424
-
425
- let(:matching_rules) do
426
- Extract.call(body: original_definition)
427
- end
428
-
429
- it "creates a Pact::SomethingLike" do
430
- expect(subject).to be_a(Pact::SomethingLike)
431
- expect(subject.to_hash).to eq original_definition.to_hash
432
- end
433
- end
434
- end
435
- end
436
- end
@@ -1,238 +0,0 @@
1
- require 'pact/matching_rules/v3/extract'
2
- require 'pact/support'
3
-
4
- module Pact
5
- module MatchingRules::V3
6
- describe Extract do
7
-
8
- describe ".call" do
9
-
10
- subject { Extract.call(matchable) }
11
-
12
- context "with a Pact::SomethingLike" do
13
- let(:matchable) do
14
- {
15
- body: Pact::SomethingLike.new(foo: 'bar', alligator: { name: 'Mary' })
16
- }
17
- end
18
-
19
- let(:rules) do
20
- {
21
- "$.body" => {
22
- "matchers" => [ {"match" => "type"} ]
23
- }
24
- }
25
- end
26
-
27
- it "creates a rule that matches by type" do
28
- expect(subject).to eq rules
29
- end
30
- end
31
-
32
- context "with a Pact::Term" do
33
- let(:matchable) do
34
- {
35
- body: {
36
- alligator: {
37
- name: Pact::Term.new(generate: 'Mary', matcher: /.*a/)
38
- }
39
- }
40
- }
41
- end
42
-
43
- let(:rules) do
44
- {
45
- "$.body.alligator.name" => {
46
- "matchers" => [ {"match" => "regex", "regex" => ".*a"} ]
47
- }
48
- }
49
- end
50
-
51
- it "creates a rule that matches by regex" do
52
- expect(subject).to eq rules
53
- end
54
- end
55
-
56
- context "with a Pact::SomethingLike containing a Term" do
57
- let(:matchable) do
58
- {
59
- body: Pact::SomethingLike.new(
60
- foo: 'bar',
61
- alligator: { name: Pact::Term.new(generate: 'Mary', matcher: /.*a/) }
62
- )
63
- }
64
- end
65
-
66
- let(:rules) do
67
- {
68
- "$.body" => {
69
- "matchers" => [ {"match" => "type"} ]
70
- },
71
- "$.body.alligator.name" => {
72
- "matchers" => [ {"match" => "regex", "regex"=>".*a"} ]
73
- },
74
- }
75
- end
76
-
77
- it "the match:regex overrides the match:type" do
78
- expect(subject).to eq rules
79
- end
80
- end
81
-
82
- context "with a Pact::SomethingLike containing an array" do
83
- let(:matchable) do
84
- {
85
- body: Pact::SomethingLike.new(
86
- alligators: [
87
- {name: 'Mary'},
88
- {name: 'Betty'}
89
- ]
90
- )
91
- }
92
- end
93
-
94
- let(:rules) do
95
- {
96
- "$.body" => {
97
- "matchers" => [ {"match" => "type"} ]
98
- }
99
- }
100
- end
101
-
102
- it "lists a rule for each item" do
103
- expect(subject).to eq rules
104
- end
105
- end
106
-
107
- context "with an ArrayLike" do
108
- let(:matchable) do
109
- {
110
- body: {
111
- alligators: Pact::ArrayLike.new(
112
- name: 'Fred'
113
- )
114
- }
115
- }
116
- end
117
-
118
- let(:rules) do
119
- {
120
- "$.body.alligators" => {
121
- "matchers" => [ {"min" => 1} ]
122
- },
123
- "$.body.alligators[*].*" => {
124
- "matchers" => [ {"match" => "type"} ]
125
- }
126
- }
127
- end
128
-
129
- it "lists a rule for all items" do
130
- expect(subject).to eq rules
131
- end
132
- end
133
-
134
- context "with an ArrayLike with a Pact::Term inside" do
135
- let(:matchable) do
136
- {
137
- body: {
138
- alligators: Pact::ArrayLike.new(
139
- name: 'Fred',
140
- phoneNumber: Pact::Term.new(generate: '1234567', matcher: /\d+/)
141
- )
142
- }
143
- }
144
- end
145
-
146
- let(:rules) do
147
- {
148
- "$.body.alligators" => {
149
- "matchers" => [ {"min" => 1} ]
150
- },
151
- "$.body.alligators[*].*" => {
152
- "matchers" => [ {"match" => "type"} ]
153
- },
154
- "$.body.alligators[*].phoneNumber" => {
155
- "matchers" => [ {"match" => "regex", "regex" => "\\d+"} ]
156
- }
157
- }
158
- end
159
-
160
- it "lists a rule that specifies that the regular expression must match" do
161
- expect(subject).to eq rules
162
- end
163
- end
164
-
165
- context "with a Pact::QueryString containing a Pact::Term" do
166
- let(:matchable) do
167
- {
168
- query: Pact::QueryString.new(Pact::Term.new(generate: 'foobar', matcher: /foo/))
169
- }
170
- end
171
-
172
- let(:rules) do
173
- {
174
- "$.query" => {
175
- "matchers" => [ {"match" => "regex", "regex" => "foo"} ]
176
- }
177
- }
178
- end
179
-
180
- it "lists a rule that specifies that the regular expression must match" do
181
- expect(subject).to eq rules
182
- end
183
- end
184
-
185
- context "with a Pact::QueryHash containing a Pact::Term" do
186
- let(:matchable) do
187
- {
188
- query: Pact::QueryHash.new(bar: Pact::Term.new(generate: 'foobar', matcher: /foo/))
189
- }
190
- end
191
-
192
- let(:rules) do
193
- {
194
- "$.query.bar[0]" => {
195
- "matchers" => [ {"match" => "regex", "regex" => "foo"} ]
196
- }
197
- }
198
- end
199
-
200
- it "lists a rule that specifies that the regular expression must match" do
201
- expect(subject).to eq rules
202
- end
203
- end
204
-
205
- context "with no special matching" do
206
- let(:matchable) do
207
- {
208
- body: { alligator: { name: 'Mary' } }
209
- }
210
- end
211
-
212
- let(:rules) do
213
- {}
214
- end
215
-
216
-
217
- it "does not create any rules" do
218
- expect(subject).to eq rules
219
- end
220
- end
221
-
222
- context "with a key containing a dot" do
223
- let(:matchable) do
224
- {
225
- "key" => {
226
- "key.with.dots" => Pact::SomethingLike.new("foo")
227
- }
228
- }
229
- end
230
-
231
- it "uses square brackets notation for the key with dots" do
232
- expect(subject.keys).to include "$.key['key.with.dots']"
233
- end
234
- end
235
- end
236
- end
237
- end
238
- end