pact-support 1.6.5 → 1.6.6

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: 0d403d886a68ff8d7dcc27760407ae9c38328347
4
- data.tar.gz: abbf6ec8fe5c0aef4d88c27861206e3ad8911a07
3
+ metadata.gz: '039bcfb7e385f534c0944984d075e419376bbfbf'
4
+ data.tar.gz: 84b10dc7ddd4ccd6d266bc2f9b7d19a605a30a33
5
5
  SHA512:
6
- metadata.gz: 784021ebd38e3b04a2ce10078af2dd1575a80a66a6e3d10008086725407c3f2a568b41be3a7198ff5d7f52c70979c1cb034d601cd1bcdf0ab482d15da0c8da48
7
- data.tar.gz: 13b5f238474aa903389b9252a76c71c0d6b416dbab8642571ac60d55100017dab53c98bd2d4b6056fe45922dba69e1984026ed6cea398a89ccf6d06269c69ea4
6
+ metadata.gz: 70d1593f05cedc8a458fd33e9b4a607d43ac63dbb54c05312472e79c39f908f0b005facc50b68e9451ac0bd6638b9be258f91de490e32d2c1bdda209cc666e46
7
+ data.tar.gz: a6340f39c1da805ca5512551938dea1de7a1e7505196cb7ad455fa44ca1aebcf0ab981a53740974c127d10f3c1965db0a2f76a0bb331bf759785eddd638eb50e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ <a name="v1.6.6"></a>
2
+ ### v1.6.6 (2018-07-25)
3
+
4
+
5
+ #### Bug Fixes
6
+
7
+ * correctly handle an 'each like' inside a 'like' ([7dc76dc](/../../commit/7dc76dc))
8
+
9
+
1
10
  <a name="v1.6.5"></a>
2
11
  ### v1.6.5 (2018-07-23)
3
12
 
@@ -92,7 +92,7 @@ module Pact
92
92
 
93
93
  def handle_match_type object, path, rules
94
94
  log_used_rule(path, 'match', 'type')
95
- Pact::SomethingLike.new(object)
95
+ Pact::SomethingLike.new(recurse(object, path))
96
96
  end
97
97
 
98
98
  def handle_regex object, path, rules
@@ -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 @expected, @root_path
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, rule), new_matching_rules |
29
- new_matching_rules[JsonPath.new(path).to_s] = rule
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
- parent_match_rule = @matching_rules[path] && @matching_rules[path]['matchers'] && @matching_rules[path]['matchers'].first && @matching_rules[path]['matchers'].first['match']
52
- 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['match']
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
- log_ignored_rules(path, rules, {'match' => 'type'})
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
- log_ignored_rules(path, rules, {'match' => 'regex', 'regex' => rules['regex']})
97
- Pact::Term.new(generate: object, matcher: Regexp.new(rules['regex']))
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 path, rules, used_rules
101
- dup_rules = rules.dup
102
- used_rules.each_pair do | used_key, used_value |
103
- dup_rules.delete(used_key) if dup_rules[used_key] == used_value
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
- if dup_rules.any?
106
- $stderr.puts "WARN: Ignoring unsupported matching rules #{dup_rules} for path #{path}"
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
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "1.6.5"
3
+ VERSION = "1.6.6"
4
4
  end
5
5
  end
@@ -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
- xit "doesn't warn about the min size being ignored" do
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.5
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-24 00:00:00.000000000 Z
15
+ date: 2018-07-25 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp