pact-support 1.5.2 → 1.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/pact/matching_rules.rb +10 -2
- data/lib/pact/matching_rules/v3/extract.rb +94 -0
- data/lib/pact/specification_version.rb +2 -2
- data/lib/pact/support/version.rb +1 -1
- data/script/release.sh +1 -1
- data/spec/lib/pact/matching_rules/v3/extract_spec.rb +238 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f9bc0e7a4c308bb14cf0e1eb4c86fa4aedc1092
|
4
|
+
data.tar.gz: d95f4eaf140fadf63bcd3fa8aeda797720b2cfb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6bb681918c1f7967c58f44467e69f871307d54c16e318f79f6c6f615593fdeec240b75b379887a3e193c9f6c78616b52b2eeae01e6cd74e172ec82ad4322363
|
7
|
+
data.tar.gz: ec0c51ec2b5c13a453d6cca32d5784fc88421e1e65bc517e3822f000852e3bf153a4c38bfa81007852e80a82e7047e5112162441afa0519fa8741e6db5370f1a
|
data/CHANGELOG.md
CHANGED
data/lib/pact/matching_rules.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'pact/matching_rules/extract'
|
2
|
+
require 'pact/matching_rules/v3/extract'
|
2
3
|
require 'pact/matching_rules/merge'
|
3
4
|
require 'pact/matching_rules/v3/merge'
|
4
5
|
|
@@ -7,11 +8,18 @@ module Pact
|
|
7
8
|
|
8
9
|
# @api public Used by pact-mock_service
|
9
10
|
def self.extract object_graph, options = {}
|
10
|
-
|
11
|
+
pact_specification_version = options[:pact_specification_version] || Pact::SpecificationVersion::NIL_VERSION
|
12
|
+
case pact_specification_version.major
|
13
|
+
when nil, 0, 1, 2
|
14
|
+
Extract.(object_graph)
|
15
|
+
else
|
16
|
+
V3::Extract.(object_graph)
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
20
|
def self.merge object_graph, matching_rules, options = {}
|
14
|
-
|
21
|
+
pact_specification_version = options[:pact_specification_version] || Pact::SpecificationVersion::NIL_VERSION
|
22
|
+
case pact_specification_version.major
|
15
23
|
when nil, 0, 1, 2
|
16
24
|
Merge.(object_graph, matching_rules)
|
17
25
|
else
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'pact/something_like'
|
2
|
+
require 'pact/array_like'
|
3
|
+
require 'pact/term'
|
4
|
+
|
5
|
+
module Pact
|
6
|
+
module MatchingRules::V3
|
7
|
+
class Extract
|
8
|
+
|
9
|
+
def self.call matchable
|
10
|
+
new(matchable).call
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize matchable
|
14
|
+
@matchable = matchable
|
15
|
+
@rules = Hash.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
recurse matchable, "$", nil
|
20
|
+
rules
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :matchable, :rules
|
26
|
+
|
27
|
+
def recurse object, path, match_type
|
28
|
+
case object
|
29
|
+
when Hash then recurse_hash(object, path, match_type)
|
30
|
+
when Array then recurse_array(object, path, match_type)
|
31
|
+
when Pact::SomethingLike then handle_something_like(object, path, match_type)
|
32
|
+
when Pact::ArrayLike then handle_array_like(object, path, match_type)
|
33
|
+
when Pact::Term then record_regex_rule object, path
|
34
|
+
when Pact::QueryString then recurse(object.query, path, match_type)
|
35
|
+
when Pact::QueryHash then recurse_hash(object.query, path, match_type)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def recurse_hash hash, path, match_type
|
40
|
+
hash.each do | (key, value) |
|
41
|
+
recurse value, "#{path}#{next_path_part(key)}", match_type
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def recurse_array new_array, path, match_type
|
46
|
+
new_array.each_with_index do | value, index |
|
47
|
+
recurse value, "#{path}[#{index}]", match_type
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def handle_something_like something_like, path, match_type
|
52
|
+
record_match_type_rule path, "type"
|
53
|
+
recurse something_like.contents, path, "type"
|
54
|
+
end
|
55
|
+
|
56
|
+
def handle_array_like array_like, path, match_type
|
57
|
+
record_rule "#{path}", 'min' => array_like.min
|
58
|
+
record_match_type_rule "#{path}[*].*", 'type'
|
59
|
+
recurse array_like.contents, "#{path}[*]", :array_like
|
60
|
+
end
|
61
|
+
|
62
|
+
def record_rule path, rule
|
63
|
+
rules[path] ||= {}
|
64
|
+
rules[path]['matchers'] ||= []
|
65
|
+
rules[path]['matchers'] << rule
|
66
|
+
end
|
67
|
+
|
68
|
+
def record_regex_rule term, path
|
69
|
+
rules[path] ||= {}
|
70
|
+
rules[path]['matchers'] ||= []
|
71
|
+
rule = { 'match' => 'regex', 'regex' => term.matcher.inspect[1..-2]}
|
72
|
+
rules[path]['matchers'] << rule
|
73
|
+
end
|
74
|
+
|
75
|
+
def record_match_type_rule path, match_type
|
76
|
+
unless match_type == :array_like || match_type.nil?
|
77
|
+
rules[path] ||= {}
|
78
|
+
rules[path]['matchers'] ||= []
|
79
|
+
rules[path]['matchers'] << { 'match' => match_type }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Beth: there's a potential bug if the key contains a dot and a single quote.
|
84
|
+
# Not sure what to do then.
|
85
|
+
def next_path_part key
|
86
|
+
if key.to_s.include?('.')
|
87
|
+
"['#{key}']"
|
88
|
+
else
|
89
|
+
".#{key}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Pact
|
2
2
|
class SpecificationVersion < Gem::Version
|
3
3
|
|
4
|
-
NIL_VERSION = Pact::SpecificationVersion.new('')
|
5
|
-
|
6
4
|
def major
|
7
5
|
segments.first
|
8
6
|
end
|
@@ -15,4 +13,6 @@ module Pact
|
|
15
13
|
major && other < major
|
16
14
|
end
|
17
15
|
end
|
16
|
+
|
17
|
+
SpecificationVersion::NIL_VERSION = Pact::SpecificationVersion.new('')
|
18
18
|
end
|
data/lib/pact/support/version.rb
CHANGED
data/script/release.sh
CHANGED
@@ -5,5 +5,5 @@ git checkout -- lib/pact/support/version.rb
|
|
5
5
|
bundle exec bump ${1:-minor} --no-commit
|
6
6
|
bundle exec rake generate_changelog
|
7
7
|
git add CHANGELOG.md lib/pact/support/version.rb
|
8
|
-
git commit -m "
|
8
|
+
git commit -m "chore(release): version $(ruby -r ./lib/pact/support/version.rb -e "puts Pact::Support::VERSION")"
|
9
9
|
bundle exec rake release
|
@@ -0,0 +1,238 @@
|
|
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
|
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.
|
4
|
+
version: 1.6.0
|
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-03
|
15
|
+
date: 2018-04-03 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: randexp
|
@@ -303,6 +303,7 @@ files:
|
|
303
303
|
- lib/pact/matching_rules/extract.rb
|
304
304
|
- lib/pact/matching_rules/jsonpath.rb
|
305
305
|
- lib/pact/matching_rules/merge.rb
|
306
|
+
- lib/pact/matching_rules/v3/extract.rb
|
306
307
|
- lib/pact/matching_rules/v3/merge.rb
|
307
308
|
- lib/pact/reification.rb
|
308
309
|
- lib/pact/rspec.rb
|
@@ -363,6 +364,7 @@ files:
|
|
363
364
|
- spec/lib/pact/matchers/unix_diff_formatter_spec.rb
|
364
365
|
- spec/lib/pact/matching_rules/extract_spec.rb
|
365
366
|
- spec/lib/pact/matching_rules/merge_spec.rb
|
367
|
+
- spec/lib/pact/matching_rules/v3/extract_spec.rb
|
366
368
|
- spec/lib/pact/matching_rules/v3/merge_spec.rb
|
367
369
|
- spec/lib/pact/matching_rules_spec.rb
|
368
370
|
- spec/lib/pact/reification_spec.rb
|
@@ -422,7 +424,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
422
424
|
version: '0'
|
423
425
|
requirements: []
|
424
426
|
rubyforge_project:
|
425
|
-
rubygems_version: 2.
|
427
|
+
rubygems_version: 2.6.11
|
426
428
|
signing_key:
|
427
429
|
specification_version: 4
|
428
430
|
summary: Shared code for Pact gems
|
@@ -465,6 +467,7 @@ test_files:
|
|
465
467
|
- spec/lib/pact/matchers/unix_diff_formatter_spec.rb
|
466
468
|
- spec/lib/pact/matching_rules/extract_spec.rb
|
467
469
|
- spec/lib/pact/matching_rules/merge_spec.rb
|
470
|
+
- spec/lib/pact/matching_rules/v3/extract_spec.rb
|
468
471
|
- spec/lib/pact/matching_rules/v3/merge_spec.rb
|
469
472
|
- spec/lib/pact/matching_rules_spec.rb
|
470
473
|
- spec/lib/pact/reification_spec.rb
|