pact-support 1.6.5 → 1.6.6
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/merge.rb +1 -1
- data/lib/pact/matching_rules/v3/merge.rb +34 -18
- data/lib/pact/support/version.rb +1 -1
- data/spec/integration/matching_rules_extract_and_merge_spec.rb +41 -4
- data/spec/lib/pact/matching_rules/v3/merge_spec.rb +25 -3
- 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: '039bcfb7e385f534c0944984d075e419376bbfbf'
|
4
|
+
data.tar.gz: 84b10dc7ddd4ccd6d266bc2f9b7d19a605a30a33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70d1593f05cedc8a458fd33e9b4a607d43ac63dbb54c05312472e79c39f908f0b005facc50b68e9451ac0bd6638b9be258f91de490e32d2c1bdda209cc666e46
|
7
|
+
data.tar.gz: a6340f39c1da805ca5512551938dea1de7a1e7505196cb7ad455fa44ca1aebcf0ab981a53740974c127d10f3c1965db0a2f76a0bb331bf759785eddd638eb50e
|
data/CHANGELOG.md
CHANGED
@@ -18,15 +18,15 @@ module Pact
|
|
18
18
|
|
19
19
|
def call
|
20
20
|
return @expected if @matching_rules.nil? || @matching_rules.empty?
|
21
|
-
recurse
|
21
|
+
recurse(@expected, @root_path).tap { log_ignored_rules }
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def standardise_paths matching_rules
|
27
27
|
return matching_rules if matching_rules.nil? || matching_rules.empty?
|
28
|
-
matching_rules.each_with_object({}) do | (path,
|
29
|
-
new_matching_rules[JsonPath.new(path).to_s] =
|
28
|
+
matching_rules.each_with_object({}) do | (path, rules), new_matching_rules |
|
29
|
+
new_matching_rules[JsonPath.new(path).to_s] = Marshal.load(Marshal.dump(rules)) # simplest way to deep clone
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -47,14 +47,14 @@ module Pact
|
|
47
47
|
end
|
48
48
|
|
49
49
|
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')
|
50
52
|
array_like_children_path = "#{path}[*]*"
|
51
|
-
|
52
|
-
|
53
|
-
min = @matching_rules[path] && @matching_rules[path]['matchers'] && @matching_rules[path]['matchers'].first && @matching_rules[path]['matchers'].first['min']
|
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
55
|
|
55
56
|
if min && (children_match_rule == 'type' || (children_match_rule.nil? && parent_match_rule == 'type'))
|
56
57
|
warn_when_not_one_example_item(array, path)
|
57
|
-
# log_ignored_rules(path, @matching_rules[path], {'min' => min})
|
58
58
|
Pact::ArrayLike.new(recurse(array.first, "#{path}[*]"), min: min)
|
59
59
|
else
|
60
60
|
new_array = []
|
@@ -82,30 +82,46 @@ module Pact
|
|
82
82
|
elsif rules['regex']
|
83
83
|
handle_regex(object, path, rules)
|
84
84
|
else
|
85
|
-
log_ignored_rules(path, rules, {})
|
85
|
+
#log_ignored_rules(path, rules, {})
|
86
86
|
object
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
def handle_match_type object, path, rules
|
91
|
-
|
92
|
-
Pact::SomethingLike.new(object)
|
91
|
+
rules.delete('match')
|
92
|
+
Pact::SomethingLike.new(recurse(object, path))
|
93
93
|
end
|
94
94
|
|
95
95
|
def handle_regex object, path, rules
|
96
|
-
|
97
|
-
|
96
|
+
rules.delete('match')
|
97
|
+
regex = rules.delete('regex')
|
98
|
+
Pact::Term.new(generate: object, matcher: Regexp.new(regex))
|
98
99
|
end
|
99
100
|
|
100
|
-
def log_ignored_rules
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
def log_ignored_rules
|
102
|
+
@matching_rules.each do | jsonpath, rules_hash |
|
103
|
+
rules_array = rules_hash["matchers"]
|
104
|
+
((rules_array.length - 1)..0).each do | index |
|
105
|
+
rules_array.delete_at(index) if rules_array[index].empty?
|
106
|
+
end
|
104
107
|
end
|
105
|
-
|
106
|
-
|
108
|
+
|
109
|
+
if @matching_rules.any?
|
110
|
+
@matching_rules.each do | path, rules_hash |
|
111
|
+
rules_hash.each do | key, value |
|
112
|
+
$stderr.puts "WARN: Ignoring unsupported #{key} #{value} for path #{path}" if value.any?
|
113
|
+
end
|
114
|
+
end
|
107
115
|
end
|
108
116
|
end
|
117
|
+
|
118
|
+
def find_rule(path, key)
|
119
|
+
@matching_rules[path] && @matching_rules[path][key]
|
120
|
+
end
|
121
|
+
|
122
|
+
def log_used_rule path, key, value
|
123
|
+
@used_rules << [path, key, value]
|
124
|
+
end
|
109
125
|
end
|
110
126
|
end
|
111
127
|
end
|
data/lib/pact/support/version.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'pact/term'
|
2
2
|
require 'pact/something_like'
|
3
3
|
require 'pact/matching_rules/extract'
|
4
|
+
require 'pact/matching_rules/v3/extract'
|
4
5
|
require 'pact/matching_rules/merge'
|
6
|
+
require 'pact/matching_rules/v3/merge'
|
5
7
|
require 'pact/reification'
|
6
8
|
|
7
9
|
describe "converting Pact::Term and Pact::SomethingLike to matching rules and back again" do
|
@@ -10,6 +12,9 @@ describe "converting Pact::Term and Pact::SomethingLike to matching rules and ba
|
|
10
12
|
let(:matching_rules) { Pact::MatchingRules::Extract.(expected) }
|
11
13
|
let(:recreated_expected) { Pact::MatchingRules::Merge.(example, matching_rules)}
|
12
14
|
|
15
|
+
let(:recreated_expected_v3) { Pact::MatchingRules::V3::Merge.(example, matching_rules_v3) }
|
16
|
+
let(:matching_rules_v3) { Pact::MatchingRules::V3::Extract.(expected) }
|
17
|
+
|
13
18
|
context "with a Pact::Term" do
|
14
19
|
let(:expected) do
|
15
20
|
{
|
@@ -21,9 +26,29 @@ describe "converting Pact::Term and Pact::SomethingLike to matching rules and ba
|
|
21
26
|
}
|
22
27
|
end
|
23
28
|
|
24
|
-
it "recreates the same object hierarchy" do
|
29
|
+
it "recreates the same object hierarchy with v2 matching" do
|
30
|
+
expect(recreated_expected).to eq expected
|
31
|
+
end
|
32
|
+
|
33
|
+
it "recreates the same object hierarchy with v3 matching" do
|
34
|
+
expect(recreated_expected_v3).to eq expected
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with a Pact::SomethingLike containing a Pact::ArrayLike" do
|
39
|
+
let(:expected) do
|
40
|
+
{
|
41
|
+
body: Pact::SomethingLike.new(children: Pact::ArrayLike.new("foo", min: 2))
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
it "recreates the same object hierarchy with v2 matching" do
|
25
46
|
expect(recreated_expected).to eq expected
|
26
47
|
end
|
48
|
+
|
49
|
+
it "recreates the same object hierarchy with v3 matching" do
|
50
|
+
expect(recreated_expected_v3).to eq expected
|
51
|
+
end
|
27
52
|
end
|
28
53
|
|
29
54
|
context "with a Pact::SomethingLike" do
|
@@ -37,9 +62,13 @@ describe "converting Pact::Term and Pact::SomethingLike to matching rules and ba
|
|
37
62
|
}
|
38
63
|
end
|
39
64
|
|
40
|
-
it "recreates the same object hierarchy" do
|
65
|
+
it "recreates the same object hierarchy with v2 matching" do
|
41
66
|
expect(recreated_expected).to eq expected
|
42
67
|
end
|
68
|
+
|
69
|
+
it "recreates the same object hierarchy with v3 matching" do
|
70
|
+
expect(recreated_expected_v3).to eq expected
|
71
|
+
end
|
43
72
|
end
|
44
73
|
|
45
74
|
context "with a Pact::SomethingLike containing a Hash" do
|
@@ -61,9 +90,13 @@ describe "converting Pact::Term and Pact::SomethingLike to matching rules and ba
|
|
61
90
|
}
|
62
91
|
end
|
63
92
|
|
64
|
-
it "recreates the same object hierarchy" do
|
93
|
+
it "recreates the same object hierarchy with v2 matching" do
|
65
94
|
expect(recreated_expected).to eq expected
|
66
95
|
end
|
96
|
+
|
97
|
+
it "recreates the same object hierarchy with v3 matching" do
|
98
|
+
expect(recreated_expected_v3).to eq expected
|
99
|
+
end
|
67
100
|
end
|
68
101
|
|
69
102
|
context "with a Pact::SomethingLike containing an Array" do
|
@@ -83,8 +116,12 @@ describe "converting Pact::Term and Pact::SomethingLike to matching rules and ba
|
|
83
116
|
}
|
84
117
|
end
|
85
118
|
|
86
|
-
it "recreates the same object hierarchy" do
|
119
|
+
it "recreates the same object hierarchy with v2 matching" do
|
87
120
|
expect(recreated_expected).to eq expected
|
88
121
|
end
|
122
|
+
|
123
|
+
it "recreates the same object hierarchy with v3 matching" do
|
124
|
+
expect(recreated_expected_v3).to eq expected
|
125
|
+
end
|
89
126
|
end
|
90
127
|
end
|
@@ -7,10 +7,16 @@ module Pact
|
|
7
7
|
subject { Merge.(expected, matching_rules) }
|
8
8
|
|
9
9
|
before do
|
10
|
-
allow($stderr).to receive(:puts)
|
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 rule deletion in Merge."
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
describe "no recognised rules" do
|
16
|
+
before do
|
17
|
+
allow($stderr).to receive(:puts)
|
18
|
+
end
|
19
|
+
|
14
20
|
let(:expected) do
|
15
21
|
{
|
16
22
|
"_links" => {
|
@@ -65,6 +71,10 @@ module Pact
|
|
65
71
|
end
|
66
72
|
|
67
73
|
describe "type based matching" do
|
74
|
+
before do
|
75
|
+
allow($stderr).to receive(:puts)
|
76
|
+
end
|
77
|
+
|
68
78
|
let(:expected) do
|
69
79
|
{
|
70
80
|
"name" => "Mary"
|
@@ -88,11 +98,19 @@ module Pact
|
|
88
98
|
subject
|
89
99
|
end
|
90
100
|
|
101
|
+
it "does not alter the passed in rules hash" do
|
102
|
+
original_matching_rules = JSON.parse(matching_rules.to_json)
|
103
|
+
subject
|
104
|
+
expect(matching_rules).to eq original_matching_rules
|
105
|
+
end
|
91
106
|
end
|
92
107
|
|
93
108
|
describe "regular expressions" do
|
94
|
-
|
95
109
|
describe "in a hash" do
|
110
|
+
before do
|
111
|
+
allow($stderr).to receive(:puts)
|
112
|
+
end
|
113
|
+
|
96
114
|
let(:expected) do
|
97
115
|
{
|
98
116
|
"_links" => {
|
@@ -275,6 +293,10 @@ module Pact
|
|
275
293
|
end
|
276
294
|
|
277
295
|
describe "with an example array with more than one item" do
|
296
|
+
before do
|
297
|
+
allow($stderr).to receive(:puts)
|
298
|
+
end
|
299
|
+
|
278
300
|
let(:expected) do
|
279
301
|
{
|
280
302
|
|
@@ -292,7 +314,7 @@ module Pact
|
|
292
314
|
}
|
293
315
|
end
|
294
316
|
|
295
|
-
|
317
|
+
it "doesn't warn about the min size being ignored" do
|
296
318
|
expect(Pact.configuration.error_stream).to receive(:puts).once
|
297
319
|
subject
|
298
320
|
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.6.
|
4
|
+
version: 1.6.6
|
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-07-
|
15
|
+
date: 2018-07-25 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: randexp
|