pact-support 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/pact/matching_rules/jsonpath.rb +60 -0
- data/lib/pact/matching_rules/merge.rb +15 -9
- data/lib/pact/support.rb +0 -1
- data/lib/pact/support/version.rb +1 -1
- data/script/update-pact-specification-v2 +9 -0
- data/spec/lib/pact/matching_rules/merge_spec.rb +19 -1
- data/spec/pact_specification/compliance-2.0.rb +2 -2
- metadata +38 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9982f639b5936295a9741ea44d3cce0dd9ce4fd6
|
4
|
+
data.tar.gz: 665084328895749ede66dbb4c355eb9c9efbde3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c806479980aa141eb70c2a5371dfdc2ea4141329664eae514a634de1c2e0c2a68b71a34faab5e0086e7ea4d26e51f730a84ebc55dbc0159f4b1b0dfa437d0da
|
7
|
+
data.tar.gz: ac8ceefbd8f194fbc597463bd24863a902fb557e925e99c832fbf095ac49c7905faaf0938d7482fc4bc9fb82861c6b290254f17b4892b4c3fe13c42df844746c
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@ Do this to generate your change history
|
|
2
2
|
|
3
3
|
git log --pretty=format:' * %h - %s (%an, %ad)'
|
4
4
|
|
5
|
+
### 0.5.1 (19 July 2015)
|
6
|
+
|
7
|
+
* bd24aff - Remove rspec require from pact/support.rb to stop rspec's let method overriding minitest's let method (Beth Skurrie, Sun Jul 19 07:49:15 2015 +1000)
|
8
|
+
* bbe9553 - Support bracket notation in matching rule jsonpaths. (Beth Skurrie, Fri Jul 10 15:16:55 2015 +1000)
|
9
|
+
|
5
10
|
### 0.5.0 (10 July 2015)
|
6
11
|
|
7
12
|
* 9451bf4 - Created helper methods for Pact::Term, SomethingLike and ArrayLike (Beth Skurrie, Fri Jul 10 11:44:45 2015 +1000)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
|
3
|
+
# Ripped with appreciation from Joshua Hull's useful JsonPath gem
|
4
|
+
# https://github.com/joshbuddy/jsonpath/blob/792ff9a928998f4252692cd3c1ba378ed931a5aa/lib/jsonpath.rb
|
5
|
+
# Only including the code that Pact needs, to reduce dependencies and potential gem version clashes.
|
6
|
+
|
7
|
+
module Pact
|
8
|
+
module MatchingRules
|
9
|
+
class JsonPath
|
10
|
+
|
11
|
+
attr_reader :path
|
12
|
+
|
13
|
+
def initialize(path)
|
14
|
+
scanner = StringScanner.new(path)
|
15
|
+
@path = []
|
16
|
+
bracket_count = 0
|
17
|
+
while not scanner.eos?
|
18
|
+
if token = scanner.scan(/\$/)
|
19
|
+
@path << token
|
20
|
+
elsif token = scanner.scan(/@/)
|
21
|
+
@path << token
|
22
|
+
elsif token = scanner.scan(/[a-zA-Z0-9_-]+/)
|
23
|
+
@path << "['#{token}']"
|
24
|
+
elsif token = scanner.scan(/'(.*?)'/)
|
25
|
+
@path << "[#{token}]"
|
26
|
+
elsif token = scanner.scan(/\[/)
|
27
|
+
count = 1
|
28
|
+
while !count.zero?
|
29
|
+
if t = scanner.scan(/\[/)
|
30
|
+
token << t
|
31
|
+
count += 1
|
32
|
+
elsif t = scanner.scan(/\]/)
|
33
|
+
token << t
|
34
|
+
count -= 1
|
35
|
+
elsif t = scanner.scan(/[^\[\]]*/)
|
36
|
+
token << t
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@path << token
|
40
|
+
elsif token = scanner.scan(/\.\./)
|
41
|
+
@path << token
|
42
|
+
elsif scanner.scan(/\./)
|
43
|
+
nil
|
44
|
+
elsif token = scanner.scan(/\*/)
|
45
|
+
@path << token
|
46
|
+
elsif token = scanner.scan(/[><=] \d+/)
|
47
|
+
@path.last << token
|
48
|
+
elsif token = scanner.scan(/./)
|
49
|
+
@path.last << token
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
path.join
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'pact/array_like'
|
2
|
+
require 'pact/matching_rules/jsonpath'
|
2
3
|
|
3
4
|
module Pact
|
4
5
|
module MatchingRules
|
@@ -10,8 +11,8 @@ module Pact
|
|
10
11
|
|
11
12
|
def initialize expected, matching_rules, root_path
|
12
13
|
@expected = expected
|
13
|
-
@matching_rules = matching_rules
|
14
|
-
@root_path = root_path
|
14
|
+
@matching_rules = standardise_paths(matching_rules)
|
15
|
+
@root_path = JsonPath.new(root_path).to_s
|
15
16
|
end
|
16
17
|
|
17
18
|
def call
|
@@ -19,6 +20,15 @@ module Pact
|
|
19
20
|
recurse @expected, @root_path
|
20
21
|
end
|
21
22
|
|
23
|
+
private
|
24
|
+
|
25
|
+
def standardise_paths matching_rules
|
26
|
+
return matching_rules if matching_rules.nil? || matching_rules.empty?
|
27
|
+
matching_rules.each_with_object({}) do | (path, rule), new_matching_rules |
|
28
|
+
new_matching_rules[JsonPath.new(path).to_s] = rule
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
22
32
|
def recurse expected, path
|
23
33
|
case expected
|
24
34
|
when Hash then recurse_hash(expected, path)
|
@@ -30,13 +40,13 @@ module Pact
|
|
30
40
|
|
31
41
|
def recurse_hash hash, path
|
32
42
|
hash.each_with_object({}) do | (k, v), new_hash |
|
33
|
-
new_path = path + "
|
43
|
+
new_path = path + "['#{k.to_s}']"
|
34
44
|
new_hash[k] = recurse(wrap(v, new_path), new_path)
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
38
48
|
def recurse_array array, path
|
39
|
-
array_like_path = "#{path}[*]
|
49
|
+
array_like_path = "#{path}[*]*"
|
40
50
|
array_match_type = @matching_rules[array_like_path] && @matching_rules[array_like_path]['match']
|
41
51
|
|
42
52
|
if array_match_type == 'type'
|
@@ -60,19 +70,15 @@ module Pact
|
|
60
70
|
end
|
61
71
|
end
|
62
72
|
|
63
|
-
# def handle_array_like
|
64
|
-
|
65
73
|
def wrap object, path
|
66
74
|
rules = @matching_rules[path]
|
67
|
-
array_rules = @matching_rules["#{path}[*]
|
75
|
+
array_rules = @matching_rules["#{path}[*]*"]
|
68
76
|
return object unless rules || array_rules
|
69
77
|
|
70
78
|
if rules['match'] == 'type'
|
71
79
|
handle_match_type(object, path, rules)
|
72
80
|
elsif rules['regex']
|
73
81
|
handle_regex(object, path, rules)
|
74
|
-
# elsif array_rules['match'] == 'type'
|
75
|
-
# handle_array_like(object, path, rules)
|
76
82
|
else
|
77
83
|
log_ignored_rules(path, rules, {})
|
78
84
|
object
|
data/lib/pact/support.rb
CHANGED
data/lib/pact/support/version.rb
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# git remote add pact-specification git@github.com:bethesque/pact-specification.git
|
4
|
+
# git fetch pact-specification
|
5
|
+
# git subtree add --prefix spec/support/pact-specification-v2 pact-specification/version-2 --squash
|
6
|
+
|
7
|
+
git remote add pact-specification git@github.com:bethesque/pact-specification.git
|
8
|
+
git fetch pact-specification
|
9
|
+
git subtree pull --prefix spec/support/pact-specification-v2 pact-specification/version-2 --squash
|
@@ -36,7 +36,7 @@ module Pact
|
|
36
36
|
expect(message).to include("WARN")
|
37
37
|
expect(message).to include("type")
|
38
38
|
expect(message).to include("unknown")
|
39
|
-
expect(message).to include("
|
39
|
+
expect(message).to include("$['body']")
|
40
40
|
end
|
41
41
|
subject
|
42
42
|
end
|
@@ -229,6 +229,24 @@ module Pact
|
|
229
229
|
end
|
230
230
|
end
|
231
231
|
end
|
232
|
+
|
233
|
+
describe "using bracket notation for a Hash" do
|
234
|
+
let(:expected) do
|
235
|
+
{
|
236
|
+
"name" => "Mary"
|
237
|
+
}
|
238
|
+
end
|
239
|
+
|
240
|
+
let(:matching_rules) do
|
241
|
+
{
|
242
|
+
"$.body['name']" => { "match" => "type" }
|
243
|
+
}
|
244
|
+
end
|
245
|
+
|
246
|
+
it "applies the rule" do
|
247
|
+
expect(subject['name']).to be_instance_of(Pact::SomethingLike)
|
248
|
+
end
|
249
|
+
end
|
232
250
|
end
|
233
251
|
end
|
234
252
|
end
|
@@ -4,14 +4,14 @@ require 'pact/consumer_contract/request'
|
|
4
4
|
require 'pact/matchers/embedded_diff_formatter'
|
5
5
|
|
6
6
|
|
7
|
-
PACT_SPEC_DIR = "
|
7
|
+
PACT_SPEC_DIR = "spec/support/pact-specification-v2/testcases"
|
8
8
|
REQUEST_TEST_CASE_FOLDERS = Dir.glob("#{PACT_SPEC_DIR}/request/**")
|
9
9
|
REQUEST_TEST_CASE_FILES = Dir.glob("#{PACT_SPEC_DIR}/request/**/*.json")
|
10
10
|
|
11
11
|
TEST_DESCRIPTIONS = {true => "matches", false => "does not match"}
|
12
12
|
TESTCASES = "**/*.json"
|
13
13
|
# TESTCASES = "array with nested array that matches.json"
|
14
|
-
describe "Pact gem complicance with Pact Specification
|
14
|
+
describe "Pact gem complicance with Pact Specification 2.0.0" do
|
15
15
|
|
16
16
|
directories = Dir.glob("#{PACT_SPEC_DIR}/request") # make this a *
|
17
17
|
|
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.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Fraser
|
@@ -12,202 +12,202 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2015-07-
|
15
|
+
date: 2015-07-18 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: randexp
|
19
19
|
requirement: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.1.7
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- -
|
28
|
+
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: 0.1.7
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: rspec
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '2.14'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - '>='
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '2.14'
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: rack-test
|
47
47
|
requirement: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- -
|
49
|
+
- - ~>
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: 0.6.2
|
52
52
|
type: :runtime
|
53
53
|
prerelease: false
|
54
54
|
version_requirements: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
|
-
- -
|
56
|
+
- - ~>
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: 0.6.2
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: awesome_print
|
61
61
|
requirement: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
|
-
- -
|
63
|
+
- - ~>
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '1.1'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
68
|
version_requirements: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
|
-
- -
|
70
|
+
- - ~>
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '1.1'
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: json
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- -
|
77
|
+
- - '>='
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
type: :runtime
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- -
|
84
|
+
- - '>='
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: term-ansicolor
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '1.0'
|
94
94
|
type: :runtime
|
95
95
|
prerelease: false
|
96
96
|
version_requirements: !ruby/object:Gem::Requirement
|
97
97
|
requirements:
|
98
|
-
- -
|
98
|
+
- - ~>
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '1.0'
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
102
|
name: find_a_port
|
103
103
|
requirement: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- -
|
105
|
+
- - ~>
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: 1.0.1
|
108
108
|
type: :runtime
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
|
-
- -
|
112
|
+
- - ~>
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: 1.0.1
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: thor
|
117
117
|
requirement: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
|
-
- -
|
119
|
+
- - '>='
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
type: :runtime
|
123
123
|
prerelease: false
|
124
124
|
version_requirements: !ruby/object:Gem::Requirement
|
125
125
|
requirements:
|
126
|
-
- -
|
126
|
+
- - '>='
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
- !ruby/object:Gem::Dependency
|
130
130
|
name: rake
|
131
131
|
requirement: !ruby/object:Gem::Requirement
|
132
132
|
requirements:
|
133
|
-
- -
|
133
|
+
- - ~>
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: 10.0.3
|
136
136
|
type: :development
|
137
137
|
prerelease: false
|
138
138
|
version_requirements: !ruby/object:Gem::Requirement
|
139
139
|
requirements:
|
140
|
-
- -
|
140
|
+
- - ~>
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: 10.0.3
|
143
143
|
- !ruby/object:Gem::Dependency
|
144
144
|
name: webmock
|
145
145
|
requirement: !ruby/object:Gem::Requirement
|
146
146
|
requirements:
|
147
|
-
- -
|
147
|
+
- - ~>
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: 1.18.0
|
150
150
|
type: :development
|
151
151
|
prerelease: false
|
152
152
|
version_requirements: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
|
-
- -
|
154
|
+
- - ~>
|
155
155
|
- !ruby/object:Gem::Version
|
156
156
|
version: 1.18.0
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: pry
|
159
159
|
requirement: !ruby/object:Gem::Requirement
|
160
160
|
requirements:
|
161
|
-
- -
|
161
|
+
- - '>='
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
164
|
type: :development
|
165
165
|
prerelease: false
|
166
166
|
version_requirements: !ruby/object:Gem::Requirement
|
167
167
|
requirements:
|
168
|
-
- -
|
168
|
+
- - '>='
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '0'
|
171
171
|
- !ruby/object:Gem::Dependency
|
172
172
|
name: fakefs
|
173
173
|
requirement: !ruby/object:Gem::Requirement
|
174
174
|
requirements:
|
175
|
-
- -
|
175
|
+
- - ~>
|
176
176
|
- !ruby/object:Gem::Version
|
177
177
|
version: '0.4'
|
178
178
|
type: :development
|
179
179
|
prerelease: false
|
180
180
|
version_requirements: !ruby/object:Gem::Requirement
|
181
181
|
requirements:
|
182
|
-
- -
|
182
|
+
- - ~>
|
183
183
|
- !ruby/object:Gem::Version
|
184
184
|
version: '0.4'
|
185
185
|
- !ruby/object:Gem::Dependency
|
186
186
|
name: hashie
|
187
187
|
requirement: !ruby/object:Gem::Requirement
|
188
188
|
requirements:
|
189
|
-
- -
|
189
|
+
- - ~>
|
190
190
|
- !ruby/object:Gem::Version
|
191
191
|
version: '2.0'
|
192
192
|
type: :development
|
193
193
|
prerelease: false
|
194
194
|
version_requirements: !ruby/object:Gem::Requirement
|
195
195
|
requirements:
|
196
|
-
- -
|
196
|
+
- - ~>
|
197
197
|
- !ruby/object:Gem::Version
|
198
198
|
version: '2.0'
|
199
199
|
- !ruby/object:Gem::Dependency
|
200
200
|
name: activesupport
|
201
201
|
requirement: !ruby/object:Gem::Requirement
|
202
202
|
requirements:
|
203
|
-
- -
|
203
|
+
- - '>='
|
204
204
|
- !ruby/object:Gem::Version
|
205
205
|
version: '0'
|
206
206
|
type: :development
|
207
207
|
prerelease: false
|
208
208
|
version_requirements: !ruby/object:Gem::Requirement
|
209
209
|
requirements:
|
210
|
-
- -
|
210
|
+
- - '>='
|
211
211
|
- !ruby/object:Gem::Version
|
212
212
|
version: '0'
|
213
213
|
description:
|
@@ -221,9 +221,9 @@ executables: []
|
|
221
221
|
extensions: []
|
222
222
|
extra_rdoc_files: []
|
223
223
|
files:
|
224
|
-
-
|
225
|
-
-
|
226
|
-
-
|
224
|
+
- .gitignore
|
225
|
+
- .rspec
|
226
|
+
- .travis.yml
|
227
227
|
- CHANGELOG.md
|
228
228
|
- Gemfile
|
229
229
|
- LICENSE.txt
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- lib/pact/matchers/unix_diff_formatter.rb
|
268
268
|
- lib/pact/matching_rules.rb
|
269
269
|
- lib/pact/matching_rules/extract.rb
|
270
|
+
- lib/pact/matching_rules/jsonpath.rb
|
270
271
|
- lib/pact/matching_rules/merge.rb
|
271
272
|
- lib/pact/reification.rb
|
272
273
|
- lib/pact/rspec.rb
|
@@ -286,6 +287,7 @@ files:
|
|
286
287
|
- lib/pact/term.rb
|
287
288
|
- lib/tasks/pact.rake
|
288
289
|
- pact-support.gemspec
|
290
|
+
- script/update-pact-specification-v2
|
289
291
|
- spec/fixtures/interaction-with-matching-rules.json
|
290
292
|
- spec/integration/matching_rules_extract_and_merge_spec.rb
|
291
293
|
- spec/lib/pact/array_like_spec.rb
|
@@ -361,17 +363,17 @@ require_paths:
|
|
361
363
|
- lib
|
362
364
|
required_ruby_version: !ruby/object:Gem::Requirement
|
363
365
|
requirements:
|
364
|
-
- -
|
366
|
+
- - '>='
|
365
367
|
- !ruby/object:Gem::Version
|
366
368
|
version: '0'
|
367
369
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
368
370
|
requirements:
|
369
|
-
- -
|
371
|
+
- - '>='
|
370
372
|
- !ruby/object:Gem::Version
|
371
373
|
version: '0'
|
372
374
|
requirements: []
|
373
375
|
rubyforge_project:
|
374
|
-
rubygems_version: 2.
|
376
|
+
rubygems_version: 2.0.14
|
375
377
|
signing_key:
|
376
378
|
specification_version: 4
|
377
379
|
summary: Shared code for Pact gems
|