pact-support 0.4.0 → 0.4.1

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: a9d55f72d24799e4cfe2fd71d535eaf37eb70c74
4
- data.tar.gz: e6c16b4858bd228d4a0d32b43bd11ac14b53bc6a
3
+ metadata.gz: 1343fbdb3d492b8bd9459ac577fdc636d3c8f907
4
+ data.tar.gz: 81a624d87c85b4a248025610281356efc28e492e
5
5
  SHA512:
6
- metadata.gz: 70a1d305f8a0655db237cbf488118f47285f5bcd08e493b597620faf6f2cad99a2a9de0f9a71f89d9fca25422564c3b69743685cfc45df9d11206e3e9925e5e0
7
- data.tar.gz: 121e1252a85b993bc22c7becb00b79430754e7e329459f4ec7c5141092b2a04e3587ec98b22c0d1bd8f4c2c027a25cb1cbc282fc2600de40033ebe4dfbd43cdc
6
+ metadata.gz: 1a8d23e47c421f2ac93136d762af05aa569292120f5c248fc03d2e2b4e7ef536b7a3a92a4c1c80f38c9be855ebd64101aad1ace927ccc2b0f205e8622ce9ccfa
7
+ data.tar.gz: c7bfe4f8db436d703354b47944761c9bfbcdaae20f2f26aaf63ac638f9235055e82208b2476c7d20eab067713fa1c26795d72198ee8166dd295c1cceef3f1951
@@ -2,6 +2,10 @@ Do this to generate your change history
2
2
 
3
3
  git log --pretty=format:' * %h - %s (%an, %ad)'
4
4
 
5
+ ### 0.4.1 (23 April 2015)
6
+
7
+ * 7da52f3 - Switch from require_relative to require to avoid double-loading when symlinks are involved (John Meredith, Thu Apr 23 14:46:03 2015 +1000)
8
+
5
9
  ### 0.4.0 (20 March 2015)
6
10
 
7
11
  * 409bde5 - support url including basic authentication info, e.g.: http://username:password@packtbroker.com (lifei zhou, Wed Mar 18 21:49:29 2015 +1100)
@@ -0,0 +1,49 @@
1
+ require 'pact/symbolize_keys'
2
+ module Pact
3
+ class ArrayLike
4
+ include SymbolizeKeys
5
+
6
+ attr_reader :contents
7
+ attr_reader :min
8
+
9
+ def initialize contents, options = {}
10
+ @contents = contents
11
+ @min = options[:min] || 1
12
+ end
13
+
14
+ def to_hash
15
+ {
16
+ :json_class => self.class.name,
17
+ :contents => contents,
18
+ :min => min
19
+ }
20
+ end
21
+
22
+ def as_json opts = {}
23
+ to_hash
24
+ end
25
+
26
+ def to_json opts = {}
27
+ as_json.to_json opts
28
+ end
29
+
30
+ def self.json_create hash
31
+ symbolized_hash = symbolize_keys(hash)
32
+ new(symbolized_hash[:contents], {min: symbolized_hash[:min]})
33
+ end
34
+
35
+ def eq other
36
+ self == other
37
+ end
38
+
39
+ def == other
40
+ other.is_a?(ArrayLike) && other.contents == self.contents && other.min == self.min
41
+ end
42
+
43
+ def generate
44
+ min.times.collect{ Pact::Reification.from_term contents }
45
+ end
46
+ end
47
+ end
48
+
49
+
@@ -6,10 +6,10 @@ require 'pact/shared/active_support_support'
6
6
  require 'date'
7
7
  require 'json/add/regexp'
8
8
  require 'open-uri'
9
- require_relative 'service_consumer'
10
- require_relative 'service_provider'
11
- require_relative 'interaction'
12
- require_relative 'pact_file'
9
+ require 'pact/consumer_contract/service_consumer'
10
+ require 'pact/consumer_contract/service_provider'
11
+ require 'pact/consumer_contract/interaction'
12
+ require 'pact/consumer_contract/pact_file'
13
13
 
14
14
  module Pact
15
15
 
@@ -72,4 +72,4 @@ module Pact
72
72
  end
73
73
 
74
74
  end
75
- end
75
+ end
@@ -19,9 +19,9 @@ module Pact
19
19
  end
20
20
 
21
21
  def self.from_hash hash
22
- request_hash = Pact::MatchingRules.merge(hash['request'], hash['request']['requestMatchingRules'])
22
+ request_hash = Pact::MatchingRules.merge(hash['request'], hash['request']['matchingRules'])
23
23
  request = Pact::Request::Expected.from_hash(request_hash)
24
- response_hash = Pact::MatchingRules.merge(hash['response'], hash['response']['responseMatchingRules'])
24
+ response_hash = Pact::MatchingRules.merge(hash['response'], hash['response']['matchingRules'])
25
25
  response = Pact::Response.from_hash(response_hash)
26
26
  new(symbolize_keys(hash).merge(request: request, response: response))
27
27
  end
@@ -1,5 +1,5 @@
1
- require_relative 'query_hash'
2
- require_relative 'query_string'
1
+ require 'pact/consumer_contract/query_hash'
2
+ require 'pact/consumer_contract/query_string'
3
3
 
4
4
  module Pact
5
5
  class Query
@@ -13,4 +13,4 @@ module Pact
13
13
  end
14
14
 
15
15
  end
16
- end
16
+ end
@@ -1,5 +1,5 @@
1
1
  require 'logger'
2
- require_relative 'configuration'
2
+ require 'pact/configuration'
3
3
 
4
4
  module Pact
5
5
  module Logging
@@ -11,4 +11,4 @@ module Pact
11
11
  Pact.configuration.logger
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1 +1 @@
1
- require_relative 'matchers/matchers'
1
+ require 'pact/matchers/matchers'
@@ -37,6 +37,7 @@ module Pact
37
37
  when Array then array_diff(expected, actual, options)
38
38
  when Regexp then regexp_diff(expected, actual, options)
39
39
  when Pact::SomethingLike then calculate_diff(expected.contents, actual, options.merge(:type => true))
40
+ when Pact::ArrayLike then array_like_diff(expected, actual, options)
40
41
  else object_diff(expected, actual, options)
41
42
  end
42
43
  end
@@ -76,6 +77,16 @@ module Pact
76
77
  diff_found ? difference : NO_DIFF
77
78
  end
78
79
 
80
+ def array_like_diff array_like, actual, options
81
+ if actual.is_a? Array
82
+ expected_size = [array_like.min, actual.size].max
83
+ expected_array = expected_size.times.collect{ Pact::Term.unpack_regexps(array_like.contents) }
84
+ actual_array_diff expected_array, actual, options.merge(:type => true)
85
+ else
86
+ Difference.new array_like.generate, actual
87
+ end
88
+ end
89
+
79
90
  def hash_diff expected, actual, options
80
91
  if actual.is_a? Hash
81
92
  actual_hash_diff expected, actual, options
@@ -21,16 +21,15 @@ module Pact
21
21
  attr_reader :matchable, :rules
22
22
 
23
23
  def recurse object, path, match_type
24
-
25
24
  case object
26
25
  when Hash then recurse_hash(object, path, match_type)
27
26
  when Array then recurse_array(object, path, match_type)
28
- when Pact::SomethingLike then recurse_something_like(object, path, match_type)
27
+ when Pact::SomethingLike then handle_something_like(object, path, match_type)
28
+ when Pact::ArrayLike then handle_array_like(object, path, match_type)
29
29
  when Pact::Term then record_regex_rule object, path
30
30
  else
31
- record_rule object, path, match_type
31
+ record_match_type_rule path, match_type
32
32
  end
33
-
34
33
  end
35
34
 
36
35
  def recurse_hash hash, path, match_type
@@ -45,19 +44,32 @@ module Pact
45
44
  end
46
45
  end
47
46
 
48
- def recurse_something_like something_like, path, match_type
47
+ def handle_something_like something_like, path, match_type
49
48
  recurse something_like.contents, path, "type"
50
49
  end
51
50
 
51
+ def handle_array_like array_like, path, match_type
52
+ record_rule "#{path}", 'min' => array_like.min
53
+ record_match_type_rule "#{path}[*].*", 'type'
54
+ recurse array_like.contents, "#{path}[*]", :array_like
55
+ end
56
+
57
+ def record_rule path, rule
58
+ rules[path] ||= {}
59
+ rules[path] = rules[path].merge(rule)
60
+ end
61
+
52
62
  def record_regex_rule term, path
53
63
  rules[path] ||= {}
54
64
  rules[path]['match'] = 'regex'
55
65
  rules[path]['regex'] = term.matcher.inspect[1..-2]
56
66
  end
57
67
 
58
- def record_rule object, path, match_type
59
- rules[path] ||= {}
60
- rules[path]['match'] = 'type'
68
+ def record_match_type_rule path, match_type
69
+ unless match_type == :array_like
70
+ rules[path] ||= {}
71
+ rules[path]['match'] = match_type
72
+ end
61
73
  end
62
74
  end
63
75
  end
@@ -1,3 +1,5 @@
1
+ require 'pact/array_like'
2
+
1
3
  module Pact
2
4
  module MatchingRules
3
5
  class Merge
@@ -34,22 +36,43 @@ module Pact
34
36
  end
35
37
 
36
38
  def recurse_array array, path
37
- new_array = []
38
- array.each_with_index do | item, index |
39
- new_path = path + "[#{index}]"
40
- new_array << recurse(wrap(item, new_path), new_path)
39
+ array_like_path = "#{path}[*].*"
40
+ array_match_type = @matching_rules[array_like_path] && @matching_rules[array_like_path]['match']
41
+
42
+ if array_match_type == 'type'
43
+ warn_when_not_one_example_item(array, path)
44
+ min = @matching_rules[path]['min']
45
+ # log_ignored_rules(path, @matching_rules[path], {'min' => min})
46
+ Pact::ArrayLike.new(recurse(array.first, "#{path}[*]"), min: min)
47
+ else
48
+ new_array = []
49
+ array.each_with_index do | item, index |
50
+ new_path = path + "[#{index}]"
51
+ new_array << recurse(wrap(item, new_path), new_path)
52
+ end
53
+ new_array
41
54
  end
42
- new_array
43
55
  end
44
56
 
57
+ def warn_when_not_one_example_item array, path
58
+ unless array.size == 1
59
+ Pact.configuration.error_stream.puts "WARN: Only the first item will be used to match the items in the array at #{path}"
60
+ end
61
+ end
62
+
63
+ # def handle_array_like
64
+
45
65
  def wrap object, path
46
66
  rules = @matching_rules[path]
47
- return object unless rules
67
+ array_rules = @matching_rules["#{path}[*].*"]
68
+ return object unless rules || array_rules
48
69
 
49
70
  if rules['match'] == 'type'
50
71
  handle_match_type(object, path, rules)
51
72
  elsif rules['regex']
52
73
  handle_regex(object, path, rules)
74
+ # elsif array_rules['match'] == 'type'
75
+ # handle_array_like(object, path, rules)
53
76
  else
54
77
  log_ignored_rules(path, rules, {})
55
78
  object
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@
7
7
  "body": {
8
8
  "name": "Mary"
9
9
  },
10
- "requestMatchingRules": {
10
+ "matchingRules": {
11
11
  "$.body.name" : {"regex" : ".+"}
12
12
  }
13
13
  },
@@ -20,7 +20,7 @@
20
20
  }
21
21
  }
22
22
  },
23
- "responseMatchingRules" : {
23
+ "matchingRules" : {
24
24
  "$.body._links.self.href": {"regex": "http:\\/\\/.*\\/\\d+"}
25
25
  }
26
26
  }
@@ -0,0 +1,37 @@
1
+ require 'pact/array_like'
2
+
3
+ module Pact
4
+ describe ArrayLike do
5
+
6
+ describe "#eq" do
7
+ subject { ArrayLike.new({name: 'Fred'}, {min: 3}) }
8
+ context "when the contents and min are the same" do
9
+ let(:other) { ArrayLike.new({name: 'Fred'}, {min: 3}) }
10
+ it "returns true" do
11
+ expect(subject).to eq other
12
+ end
13
+
14
+ end
15
+ context "when the contents are different" do
16
+ let(:other) { ArrayLike.new({name: 'John'}, {min: 3}) }
17
+ it "returns false" do
18
+ expect(subject).to_not eq other
19
+ end
20
+ end
21
+ context "when the min is different" do
22
+ let(:other) { ArrayLike.new({name: 'Fred'}, {min: 1}) }
23
+ it "returns false" do
24
+ expect(subject).to_not eq other
25
+ end
26
+ end
27
+ end
28
+
29
+ subject { ArrayLike.new({name: Pact::Term.new(generate: 'Fred', matcher: /F/)}, {min: 2}) }
30
+
31
+ describe "#generate" do
32
+ it "creates an array with the reified example" do
33
+ expect(subject.generate).to eq [{name: 'Fred'},{name: 'Fred'}]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,207 @@
1
+ require 'pact/matchers'
2
+
3
+ module Pact
4
+ describe Matchers do
5
+
6
+ include Pact::Matchers
7
+
8
+ let(:min) { 1 }
9
+ let(:expected) do
10
+ {
11
+ animals: Pact::ArrayLike.new({name: 'Fred'}, {min: min})
12
+ }
13
+ end
14
+
15
+ let(:difference) { diff(expected, actual) }
16
+
17
+ context "when each element in the array matches by type" do
18
+ let(:actual) do
19
+ {
20
+ animals: [{name: 'Susan'}, {name: 'Janet'}]
21
+ }
22
+ end
23
+ it "matches" do
24
+ expect(difference).to be_empty
25
+ end
26
+ end
27
+
28
+ context "when each element in the array does not match by type" do
29
+ let(:actual) do
30
+ {
31
+ animals: [{name: 'Susan'}, {name: 1}]
32
+ }
33
+ end
34
+ let(:expected_difference) do
35
+ {
36
+ animals: [
37
+ Pact::Matchers::NoDiffAtIndex.new,
38
+ {
39
+ name: Pact::Matchers::TypeDifference.new(ExpectedType.new('Fred'), ActualType.new(1))
40
+ }
41
+ ]
42
+ }
43
+ end
44
+ it "returns a diff" do
45
+ expect(difference).to eq expected_difference
46
+ end
47
+ end
48
+
49
+ context "when an ArrayLike is expected but a hash is found" do
50
+ let(:actual) do
51
+ {
52
+ animals: {
53
+ some: 'Animals'
54
+ }
55
+ }
56
+ end
57
+ let(:expected_difference) do
58
+ {
59
+ animals: Matchers::Difference.new([{name: 'Fred'}], {some: 'Animals'})
60
+ }
61
+ end
62
+ it "returns a diff" do
63
+ expect(difference).to eq expected_difference
64
+ end
65
+ end
66
+
67
+ context "when an ArrayLike is expected but nil found" do
68
+ let(:actual) do
69
+ {
70
+ animals: nil
71
+ }
72
+ end
73
+ let(:expected_difference) do
74
+ {
75
+ animals: Matchers::Difference.new([{name: 'Fred'}], nil)
76
+ }
77
+ end
78
+ it "returns a diff" do
79
+ expect(difference).to eq expected_difference
80
+ end
81
+ end
82
+
83
+ context "when an ArrayLike is expected but an empty array is found" do
84
+ let(:actual) do
85
+ {
86
+ animals: []
87
+ }
88
+ end
89
+ let(:expected_difference) do
90
+ {
91
+ animals: [Matchers::Difference.new({name: 'Fred'}, Pact::IndexNotFound.new)]
92
+ }
93
+ end
94
+ it "returns a diff" do
95
+ expect(difference).to eq expected_difference
96
+ end
97
+ end
98
+
99
+ context "when an ArrayLike is expected but the actual does not have enough elements in it" do
100
+ let(:min) { 2 }
101
+ let(:actual) do
102
+ {
103
+ animals: [{name: 'Susan'}]
104
+ }
105
+ end
106
+ let(:expected_difference) do
107
+ {
108
+ animals: [Pact::Matchers::NoDiffAtIndex.new, Matchers::Difference.new({name: 'Fred'}, Pact::IndexNotFound.new)]
109
+ }
110
+ end
111
+ it "returns a diff" do
112
+ expect(difference).to eq expected_difference
113
+ end
114
+ end
115
+
116
+ context "when an ArrayLike is expected with a Pact::Term in it" do
117
+ let(:expected) do
118
+ {
119
+ animals: Pact::ArrayLike.new(name: Pact::Term.new(generate: 'Fred', matcher: /F/))
120
+ }
121
+ end
122
+ let(:actual) do
123
+ {
124
+ animals: [{name: 'Susan'}]
125
+ }
126
+ end
127
+ let(:expected_difference) do
128
+ {
129
+ animals: [{name: Matchers::RegexpDifference.new(/F/, 'Susan')}]
130
+ }
131
+ end
132
+ it "returns a diff" do
133
+ expect(difference).to eq expected_difference
134
+ end
135
+ end
136
+
137
+ context "when an ArrayLike is expected within an ArrayLike and they match" do
138
+ let(:expected) do
139
+ {
140
+ animals: Pact::ArrayLike.new(
141
+ name: 'Fred',
142
+ children: Pact::ArrayLike.new(
143
+ age: 8
144
+ )
145
+ )
146
+ }
147
+ end
148
+ let(:actual) do
149
+ {
150
+ animals: [
151
+ {
152
+ name: 'Susan',
153
+ children: [
154
+ {age: 4},{age: 5}
155
+ ]
156
+ }
157
+ ]
158
+ }
159
+ end
160
+ it "returns an empty diff" do
161
+ expect(difference).to be_empty
162
+ end
163
+ end
164
+
165
+ context "when an ArrayLike is expected within an ArrayLike and they don't match" do
166
+ let(:expected) do
167
+ {
168
+ animals: Pact::ArrayLike.new(
169
+ name: 'Fred',
170
+ children: Pact::ArrayLike.new(
171
+ age: 8
172
+ )
173
+ )
174
+ }
175
+ end
176
+ let(:actual) do
177
+ {
178
+ animals: [
179
+ {
180
+ name: 'Susan',
181
+ children: [
182
+ {age: 4},{foo: 'bar'}
183
+ ]
184
+ }
185
+ ]
186
+ }
187
+ end
188
+ let(:expected_difference) do
189
+ {
190
+ animals: [
191
+ {
192
+ children: [
193
+ Matchers::NoDiffAtIndex.new,
194
+ {
195
+ age: Matchers::TypeDifference.new(ExpectedType.new(8), KeyNotFound.new)
196
+ }
197
+ ]
198
+ }
199
+ ]
200
+ }
201
+ end
202
+ it "returns the diff" do
203
+ expect(difference).to eq expected_difference
204
+ end
205
+ end
206
+ end
207
+ end
@@ -1,5 +1,6 @@
1
1
  require 'pact/matching_rules/extract'
2
2
  require 'pact/something_like'
3
+ require 'pact/array_like'
3
4
  require 'pact/term'
4
5
 
5
6
  module Pact
@@ -99,6 +100,54 @@ module Pact
99
100
  expect(subject).to eq rules
100
101
  end
101
102
  end
103
+
104
+ context "with an ArrayLike" do
105
+ let(:matchable) do
106
+ {
107
+ body: {
108
+ alligators: Pact::ArrayLike.new(
109
+ name: 'Fred'
110
+ )
111
+ }
112
+ }
113
+ end
114
+
115
+ let(:rules) do
116
+ {
117
+ "$.body.alligators" => {"min" => 1},
118
+ "$.body.alligators[*].*" => {"match" => "type"}
119
+ }
120
+ end
121
+
122
+ it "lists a rule for all items" do
123
+ expect(subject).to eq rules
124
+ end
125
+ end
126
+
127
+ context "with an ArrayLike with a Pact::Term inside" do
128
+ let(:matchable) do
129
+ {
130
+ body: {
131
+ alligators: Pact::ArrayLike.new(
132
+ name: 'Fred',
133
+ phoneNumber: Pact::Term.new(generate: '1234567', matcher: /\d+/)
134
+ )
135
+ }
136
+ }
137
+ end
138
+
139
+ let(:rules) do
140
+ {
141
+ "$.body.alligators" => {"min" => 1},
142
+ "$.body.alligators[*].*" => {"match" => "type"},
143
+ "$.body.alligators[*].phoneNumber" => {"match" => "regex", "regex" => "\\d+"}
144
+ }
145
+ end
146
+
147
+ it "lists a rule that specifies that the regular expression must match" do
148
+ expect(subject).to eq rules
149
+ end
150
+ end
102
151
  end
103
152
  end
104
153
  end
@@ -142,6 +142,92 @@ module Pact
142
142
  expect(subject["_links"]["self"][0]["href"].matcher.inspect).to eq "/http:\\/\\/.*\\/thing/"
143
143
  end
144
144
  end
145
+
146
+ describe "with an array where all elements should match by type" do
147
+ let(:expected) do
148
+ {
149
+
150
+ 'alligators' => [
151
+ {'name' => 'Mary'}
152
+ ]
153
+
154
+ }
155
+ end
156
+
157
+ let(:matching_rules) do
158
+ {
159
+ "$.body.alligators" => { 'min' => 2 },
160
+ "$.body.alligators[*].*" => { 'match' => 'type'}
161
+ }
162
+ end
163
+ it "creates a Pact::ArrayLike at the appropriate path" do
164
+ expect(subject["alligators"]).to be_instance_of(Pact::ArrayLike)
165
+ expect(subject["alligators"].contents).to eq 'name' => 'Mary'
166
+ expect(subject["alligators"].min).to eq 2
167
+ end
168
+ end
169
+
170
+ describe "with an array where all elements should match by type nested inside another array where all elements should match by type" do
171
+ let(:expected) do
172
+ {
173
+
174
+ 'alligators' => [
175
+ {
176
+ 'name' => 'Mary',
177
+ 'children' => [
178
+ 'age' => 9
179
+ ]
180
+ }
181
+ ]
182
+
183
+ }
184
+ end
185
+
186
+ let(:matching_rules) do
187
+ {
188
+ "$.body.alligators" => { 'min' => 2 },
189
+ "$.body.alligators[*].*" => { 'match' => 'type'},
190
+ "$.body.alligators[*].children" => { 'min' => 1 },
191
+ "$.body.alligators[*].children[*].*" => { 'match' => 'type'}
192
+ }
193
+ end
194
+ it "creates a Pact::ArrayLike at the appropriate path" do
195
+ expect(subject["alligators"].contents['children']).to be_instance_of(Pact::ArrayLike)
196
+ expect(subject["alligators"].contents['children'].contents).to eq 'age' => 9
197
+ expect(subject["alligators"].contents['children'].min).to eq 1
198
+ end
199
+ end
200
+
201
+ describe "with an example array with more than one item" do
202
+ let(:expected) do
203
+ {
204
+
205
+ 'alligators' => [
206
+ {'name' => 'Mary'},
207
+ {'name' => 'Joe'}
208
+ ]
209
+
210
+ }
211
+ end
212
+
213
+ let(:matching_rules) do
214
+ {
215
+ "$.body.alligators" => { 'min' => 2 },
216
+ "$.body.alligators[*].*" => { 'match' => 'type'}
217
+ }
218
+ end
219
+
220
+ xit "doesn't warn about the min size being ignored" do
221
+ expect(Pact.configuration.error_stream).to receive(:puts).once
222
+ subject
223
+ end
224
+
225
+ it "warns that the other items will be ignored" do
226
+ allow(Pact.configuration.error_stream).to receive(:puts)
227
+ expect(Pact.configuration.error_stream).to receive(:puts).with(/WARN: Only the first item/)
228
+ subject
229
+ end
230
+ end
145
231
  end
146
232
  end
147
233
  end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'pact/consumer/request'
3
+ require 'pact/consumer_contract/request'
4
+ require 'pact/matchers/embedded_diff_formatter'
5
+
6
+
7
+ PACT_SPEC_DIR = "../pact-specification/testcases"
8
+ REQUEST_TEST_CASE_FOLDERS = Dir.glob("#{PACT_SPEC_DIR}/request/**")
9
+ REQUEST_TEST_CASE_FILES = Dir.glob("#{PACT_SPEC_DIR}/request/**/*.json")
10
+
11
+ TEST_DESCRIPTIONS = {true => "matches", false => "does not match"}
12
+ TESTCASES = "**/*.json"
13
+ # TESTCASES = "array with nested array that matches.json"
14
+ describe "Pact gem complicance with Pact Specification 1.0.0" do
15
+
16
+ directories = Dir.glob("#{PACT_SPEC_DIR}/request") # make this a *
17
+
18
+ directories.each do | dir_name |
19
+
20
+ describe File.basename(dir_name) do
21
+
22
+ sub_directories = Dir.glob("#{dir_name}/*")
23
+
24
+ sub_directories.each do | sub_dir_name |
25
+
26
+ context File.basename(sub_dir_name) do
27
+ testcases = Dir.glob("#{sub_dir_name}/#{TESTCASES}")
28
+
29
+ testcases.each do | file_name |
30
+
31
+ context File.basename(file_name).chomp(".json") do
32
+
33
+ file_content = nil
34
+ begin
35
+ file_content = File.read(file_name)
36
+ test_content = JSON.parse(file_content)
37
+ default = {'query' => '', 'headers' => {}}
38
+
39
+ request_hash = Pact::MatchingRules.merge(test_content["expected"], test_content["expected"]['matchingRules'])
40
+ expected = Pact::Request::Expected.from_hash(default.merge(request_hash))
41
+
42
+ # expected = Pact::Request::Expected.from_hash(default.merge(test_content["expected"]))
43
+ actual = Pact::Consumer::Request::Actual.from_hash(default.merge(test_content["actual"]))
44
+ expected_result = test_content.fetch("match")
45
+ comment = test_content["comment"]
46
+
47
+ it "#{TEST_DESCRIPTIONS[expected_result]} - #{comment}" do
48
+ matches = expected.matches?(actual)
49
+ if matches != expected_result
50
+ puts Pact::Matchers::EmbeddedDiffFormatter.call(expected.difference(actual))
51
+ end
52
+ expect(matches).to eq expected_result
53
+ end
54
+ rescue => e
55
+ puts "Error parsing json from #{file_name}, #{e.message}: #{file_content}"
56
+ raise e
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ 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: 0.4.0
4
+ version: 0.4.1
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: 2015-03-20 00:00:00.000000000 Z
15
+ date: 2015-04-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp
@@ -230,6 +230,7 @@ files:
230
230
  - README.md
231
231
  - RELEASING.md
232
232
  - Rakefile
233
+ - lib/pact/array_like.rb
233
234
  - lib/pact/configuration.rb
234
235
  - lib/pact/consumer/request.rb
235
236
  - lib/pact/consumer_contract.rb
@@ -286,6 +287,7 @@ files:
286
287
  - pact-support.gemspec
287
288
  - spec/fixtures/interaction-with-matching-rules.json
288
289
  - spec/integration/matching_rules_extract_and_merge_spec.rb
290
+ - spec/lib/pact/array_like_spec.rb
289
291
  - spec/lib/pact/configuration_spec.rb
290
292
  - spec/lib/pact/consumer/request_spec.rb
291
293
  - spec/lib/pact/consumer_contract/active_support_support_spec.rb
@@ -302,6 +304,7 @@ files:
302
304
  - spec/lib/pact/matchers/embedded_diff_formatter_spec.rb
303
305
  - spec/lib/pact/matchers/index_not_found_spec.rb
304
306
  - spec/lib/pact/matchers/list_diff_formatter_spec.rb
307
+ - spec/lib/pact/matchers/matchers_array_like_spec.rb
305
308
  - spec/lib/pact/matchers/matchers_spec.rb
306
309
  - spec/lib/pact/matchers/no_diff_at_index_spec.rb
307
310
  - spec/lib/pact/matchers/regexp_difference_spec.rb
@@ -320,6 +323,7 @@ files:
320
323
  - spec/lib/pact/shared/text_differ_spec.rb
321
324
  - spec/lib/pact/something_like_spec.rb
322
325
  - spec/lib/pact/term_spec.rb
326
+ - spec/pact_specification/compliance-2.0.rb
323
327
  - spec/spec_helper.rb
324
328
  - spec/support/a_consumer-a_producer.json
325
329
  - spec/support/a_consumer-a_provider.json
@@ -370,6 +374,7 @@ summary: Shared code for Pact gems
370
374
  test_files:
371
375
  - spec/fixtures/interaction-with-matching-rules.json
372
376
  - spec/integration/matching_rules_extract_and_merge_spec.rb
377
+ - spec/lib/pact/array_like_spec.rb
373
378
  - spec/lib/pact/configuration_spec.rb
374
379
  - spec/lib/pact/consumer/request_spec.rb
375
380
  - spec/lib/pact/consumer_contract/active_support_support_spec.rb
@@ -386,6 +391,7 @@ test_files:
386
391
  - spec/lib/pact/matchers/embedded_diff_formatter_spec.rb
387
392
  - spec/lib/pact/matchers/index_not_found_spec.rb
388
393
  - spec/lib/pact/matchers/list_diff_formatter_spec.rb
394
+ - spec/lib/pact/matchers/matchers_array_like_spec.rb
389
395
  - spec/lib/pact/matchers/matchers_spec.rb
390
396
  - spec/lib/pact/matchers/no_diff_at_index_spec.rb
391
397
  - spec/lib/pact/matchers/regexp_difference_spec.rb
@@ -404,6 +410,7 @@ test_files:
404
410
  - spec/lib/pact/shared/text_differ_spec.rb
405
411
  - spec/lib/pact/something_like_spec.rb
406
412
  - spec/lib/pact/term_spec.rb
413
+ - spec/pact_specification/compliance-2.0.rb
407
414
  - spec/spec_helper.rb
408
415
  - spec/support/a_consumer-a_producer.json
409
416
  - spec/support/a_consumer-a_provider.json
@@ -426,4 +433,3 @@ test_files:
426
433
  - spec/support/test_app_fail.json
427
434
  - spec/support/test_app_pass.json
428
435
  - spec/support/test_app_with_right_content_type_differ.json
429
- has_rdoc: