pact-support 1.16.1 → 1.16.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/README.md +1 -1
- data/lib/pact/consumer_contract/interaction_v2_parser.rb +12 -2
- data/lib/pact/consumer_contract/query.rb +18 -2
- data/lib/pact/consumer_contract/query_hash.rb +5 -2
- data/lib/pact/reification.rb +13 -9
- data/lib/pact/shared/active_support_support.rb +27 -15
- data/lib/pact/shared/request.rb +13 -4
- data/lib/pact/support/version.rb +1 -1
- data/lib/pact/term.rb +5 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87344137693fa6e4f3a31d9794ab10a09680cebc96d5caaa62b9191b54643347
|
4
|
+
data.tar.gz: 4ee4e677c7d144e5fef6bf93ee568ee9a8f588bd04ba6b13b0c45bc7ddb044b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d9067f4a4582fc58ed8e74abc6201ec21060701f9baf7e40fcbc4887982aafef05afa1a11534bca492e57253ee37f91a764dd03c81abaa4d62cb90976f178a
|
7
|
+
data.tar.gz: 607223093f8ec2b7adb4415d229cfa2a0ed2fa2a74e633ed444d61ac2b9775b7097ea11d8b1dc70873b33249cb44c8f7f86ab42c9bbe1369367b99da7cddc77f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,39 @@
|
|
1
|
+
<a name="v1.16.6"></a>
|
2
|
+
### v1.16.6 (2021-01-28)
|
3
|
+
|
4
|
+
#### Bug Fixes
|
5
|
+
|
6
|
+
* raise Pact::Error not RuntimeError when invalid constructor arguments are supplied to a Pact::Term ([d9fb8ea](/../../commit/d9fb8ea))
|
7
|
+
* update active support support for Ruby 3.0 ([6c30d42](/../../commit/6c30d42))
|
8
|
+
|
9
|
+
<a name="v1.16.5"></a>
|
10
|
+
### v1.16.5 (2020-11-25)
|
11
|
+
|
12
|
+
#### Bug Fixes
|
13
|
+
|
14
|
+
* maintain the original string query for the provider verification while also parsing the string query into a hash to allow the matching rules to be applied correctly for use in the mock service on the consumer side ([12105dd](/../../commit/12105dd))
|
15
|
+
|
16
|
+
<a name="v1.16.4"></a>
|
17
|
+
### v1.16.4 (2020-11-13)
|
18
|
+
|
19
|
+
#### Bug Fixes
|
20
|
+
|
21
|
+
* ensure expected and actual query strings are parsed consistently ([4e9ca9c](/../../commit/4e9ca9c))
|
22
|
+
|
23
|
+
<a name="v1.16.3"></a>
|
24
|
+
### v1.16.3 (2020-11-10)
|
25
|
+
|
26
|
+
#### Bug Fixes
|
27
|
+
|
28
|
+
* add missing params_hash_has_key ([700efa7](/../../commit/700efa7))
|
29
|
+
|
30
|
+
<a name="v1.16.2"></a>
|
31
|
+
### v1.16.2 (2020-11-07)
|
32
|
+
|
33
|
+
#### Bug Fixes
|
34
|
+
|
35
|
+
* removed undefined depth from query ([53a373d](/../../commit/53a373d))
|
36
|
+
|
1
37
|
<a name="v1.16.1"></a>
|
2
38
|
### v1.16.1 (2020-11-06)
|
3
39
|
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Pact Support
|
2
2
|
|
3
|
-
|
3
|
+
![Build status](https://github.com/pact-foundation/pact-support/workflows/Test/badge.svg)
|
4
4
|
|
5
5
|
Provides shared code for the Pact gems
|
@@ -23,12 +23,22 @@ module Pact
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.parse_request request_hash, options
|
26
|
-
|
26
|
+
original_query_string = request_hash['query']
|
27
|
+
query_is_string = original_query_string.is_a?(String)
|
28
|
+
if query_is_string
|
27
29
|
request_hash = request_hash.dup
|
28
30
|
request_hash['query'] = Pact::Query.parse_string(request_hash['query'])
|
29
31
|
end
|
32
|
+
# The query has to be a hash at this stage for the matching rules to be applied
|
30
33
|
request_hash = Pact::MatchingRules.merge(request_hash, request_hash['matchingRules'], options)
|
31
|
-
|
34
|
+
# The original query string needs to be passed in to the constructor so it can be used
|
35
|
+
# when the request is replayed. Otherwise, we loose the square brackets because they get lost
|
36
|
+
# in the translation between string => structured object, as we don't know/store which
|
37
|
+
# query string convention was used.
|
38
|
+
if query_is_string
|
39
|
+
request_hash['query'] = Pact::QueryHash.new(request_hash['query'], original_query_string)
|
40
|
+
end
|
41
|
+
request = Pact::Request::Expected.from_hash(request_hash)
|
32
42
|
end
|
33
43
|
|
34
44
|
def self.parse_response response_hash, options
|
@@ -14,11 +14,15 @@ module Pact
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.is_a_query_object?(object)
|
18
|
+
object.is_a?(Pact::QueryHash) || object.is_a?(Pact::QueryString)
|
19
|
+
end
|
20
|
+
|
17
21
|
def self.parse_string query_string
|
18
22
|
parsed_query = parse_query(query_string)
|
19
23
|
|
20
24
|
# If Rails nested params...
|
21
|
-
if parsed_query.keys.any?{ | key| key
|
25
|
+
if parsed_query.keys.any?{ | key| key =~ /\[.*\]/ }
|
22
26
|
parse_nested_query(query_string)
|
23
27
|
else
|
24
28
|
parsed_query.each_with_object({}) do | (key, value), new_hash |
|
@@ -99,7 +103,7 @@ module Pact
|
|
99
103
|
else
|
100
104
|
params[k] ||= {}
|
101
105
|
raise ParameterTypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params_hash_type?(params[k])
|
102
|
-
params[k] = normalize_params(params[k], after, v
|
106
|
+
params[k] = normalize_params(params[k], after, v)
|
103
107
|
end
|
104
108
|
|
105
109
|
params
|
@@ -109,6 +113,18 @@ module Pact
|
|
109
113
|
obj.is_a?(Hash)
|
110
114
|
end
|
111
115
|
|
116
|
+
def self.params_hash_has_key?(hash, key)
|
117
|
+
return false if key =~ /\[\]/
|
118
|
+
|
119
|
+
key.split(/[\[\]]+/).inject(hash) do |h, part|
|
120
|
+
next h if part == ''
|
121
|
+
return false unless params_hash_type?(h) && h.key?(part)
|
122
|
+
h[part]
|
123
|
+
end
|
124
|
+
|
125
|
+
true
|
126
|
+
end
|
127
|
+
|
112
128
|
def self.unescape(s, encoding = Encoding::UTF_8)
|
113
129
|
URI.decode_www_form_component(s, encoding)
|
114
130
|
end
|
@@ -8,8 +8,11 @@ module Pact
|
|
8
8
|
include ActiveSupportSupport
|
9
9
|
include SymbolizeKeys
|
10
10
|
|
11
|
-
|
11
|
+
attr_reader :original_string
|
12
|
+
|
13
|
+
def initialize(query, original_string = nil)
|
12
14
|
@hash = query.nil? ? query : convert_to_hash_of_arrays(query)
|
15
|
+
@original_string = original_string
|
13
16
|
end
|
14
17
|
|
15
18
|
def as_json(opts = {})
|
@@ -32,7 +35,7 @@ module Pact
|
|
32
35
|
# from the actual query string.
|
33
36
|
def difference(other)
|
34
37
|
require 'pact/matchers' # avoid recursive loop between this file, pact/reification and pact/matchers
|
35
|
-
Pact::Matchers.diff(query, symbolize_keys(
|
38
|
+
Pact::Matchers.diff(query, symbolize_keys(convert_to_hash_of_arrays(Query.parse_string(other.query))), allow_unexpected_keys: false)
|
36
39
|
end
|
37
40
|
|
38
41
|
def query
|
data/lib/pact/reification.rb
CHANGED
@@ -27,15 +27,19 @@ module Pact
|
|
27
27
|
when Pact::QueryString
|
28
28
|
from_term(term.query)
|
29
29
|
when Pact::QueryHash
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
v.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
if term.original_string
|
31
|
+
term.original_string
|
32
|
+
else
|
33
|
+
from_term(term.query).map { |k, v|
|
34
|
+
if v.nil?
|
35
|
+
k
|
36
|
+
elsif v.is_a?(Array) #For cases where there are multiple instance of the same parameter
|
37
|
+
v.map { |x| "#{k}=#{escape(x)}"}.join('&')
|
38
|
+
else
|
39
|
+
"#{k}=#{escape(v)}"
|
40
|
+
end
|
41
|
+
}.join('&')
|
42
|
+
end
|
39
43
|
when Pact::StringWithMatchingRules
|
40
44
|
String.new(term)
|
41
45
|
else
|
@@ -2,22 +2,28 @@
|
|
2
2
|
|
3
3
|
module Pact
|
4
4
|
module ActiveSupportSupport
|
5
|
-
|
6
5
|
extend self
|
7
6
|
|
8
7
|
def fix_all_the_things thing
|
9
|
-
if
|
10
|
-
|
11
|
-
|
12
|
-
thing.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
if defined?(ActiveSupport)
|
9
|
+
if thing.is_a?(Regexp)
|
10
|
+
fix_regexp(thing)
|
11
|
+
elsif thing.is_a?(Array)
|
12
|
+
thing.collect{ | it | fix_all_the_things it }
|
13
|
+
elsif thing.is_a?(Hash)
|
14
|
+
thing.each_with_object({}) { | (k, v), new_hash | new_hash[k] = fix_all_the_things(v) }
|
15
|
+
elsif thing.is_a?(Pact::Term)
|
16
|
+
# matcher Regexp is fixed in its own as_json method
|
17
|
+
thing
|
18
|
+
elsif thing.class.name.start_with?("Pact")
|
19
|
+
warn_about_regexp(thing)
|
20
|
+
thing
|
21
|
+
else
|
22
|
+
thing
|
18
23
|
end
|
24
|
+
else
|
25
|
+
thing
|
19
26
|
end
|
20
|
-
thing
|
21
27
|
end
|
22
28
|
|
23
29
|
# ActiveSupport JSON overwrites (i.e. TRAMPLES) the json methods of the Regexp class directly
|
@@ -27,10 +33,7 @@ module Pact
|
|
27
33
|
# original as_json to the Regexp instances in the ConsumerContract before we write them to the
|
28
34
|
# pact file. If anyone can find a better way, please submit a pull request ASAP!
|
29
35
|
def fix_regexp regexp
|
30
|
-
|
31
|
-
{:json_class => 'Regexp', "o" => self.options, "s" => self.source }
|
32
|
-
end
|
33
|
-
regexp
|
36
|
+
{:json_class => 'Regexp', "o" => regexp.options, "s" => regexp.source }
|
34
37
|
end
|
35
38
|
|
36
39
|
# Having Active Support JSON loaded somehow kills the formatting of pretty_generate for objects.
|
@@ -49,5 +52,14 @@ module Pact
|
|
49
52
|
json.gsub(/\\u([0-9A-Za-z]{4})/) {|s| [$1.to_i(16)].pack("U")}
|
50
53
|
end
|
51
54
|
|
55
|
+
def warn_about_regexp(thing)
|
56
|
+
thing.instance_variables.each do | iv_name |
|
57
|
+
iv = thing.instance_variable_get(iv_name)
|
58
|
+
if iv.is_a?(Regexp)
|
59
|
+
require 'pact/configuration'
|
60
|
+
Pact.configuration.error_stream.puts("WARN: Instance variable #{iv_name} for class #{thing.class.name} is a Regexp and isn't been serialized properly. Please raise an issue at https://github.com/pact-foundation/pact-support/issues/new.")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
52
64
|
end
|
53
65
|
end
|
data/lib/pact/shared/request.rb
CHANGED
@@ -3,9 +3,7 @@ require 'pact/consumer_contract/headers'
|
|
3
3
|
require 'pact/consumer_contract/query'
|
4
4
|
|
5
5
|
module Pact
|
6
|
-
|
7
6
|
module Request
|
8
|
-
|
9
7
|
class Base
|
10
8
|
include Pact::SymbolizeKeys
|
11
9
|
|
@@ -16,7 +14,7 @@ module Pact
|
|
16
14
|
@path = path
|
17
15
|
@headers = Hash === headers ? Headers.new(headers) : headers # Could be a NullExpectation - TODO make this more elegant
|
18
16
|
@body = body
|
19
|
-
|
17
|
+
set_query(query)
|
20
18
|
end
|
21
19
|
|
22
20
|
def to_hash
|
@@ -92,6 +90,17 @@ module Pact
|
|
92
90
|
(query.nil? || query.empty?) ? '' : "?#{Pact::Reification.from_term(query)}"
|
93
91
|
end
|
94
92
|
|
93
|
+
def set_query(query)
|
94
|
+
@query = if is_unspecified?(query)
|
95
|
+
query
|
96
|
+
else
|
97
|
+
if Pact::Query.is_a_query_object?(query)
|
98
|
+
query
|
99
|
+
else
|
100
|
+
Pact::Query.create(query)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
95
104
|
end
|
96
105
|
end
|
97
|
-
end
|
106
|
+
end
|
data/lib/pact/support/version.rb
CHANGED
data/lib/pact/term.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'pact/shared/active_support_support'
|
2
2
|
require 'json/add/regexp'
|
3
|
+
require 'pact/errors'
|
3
4
|
|
4
5
|
module Pact
|
5
6
|
class Term
|
@@ -25,13 +26,13 @@ module Pact
|
|
25
26
|
def initialize(attributes = {})
|
26
27
|
@generate = attributes[:generate]
|
27
28
|
@matcher = attributes[:matcher]
|
28
|
-
raise "Please specify a matcher for the Term" unless @matcher != nil
|
29
|
-
raise "Please specify a value to generate for the Term" unless @generate != nil
|
30
|
-
raise "Value to generate \"#{@generate}\" does not match regular expression #{@matcher.inspect}" unless @generate =~ @matcher
|
29
|
+
raise Pact::Error.new("Please specify a matcher for the Term") unless @matcher != nil
|
30
|
+
raise Pact::Error.new("Please specify a value to generate for the Term") unless @generate != nil
|
31
|
+
raise Pact::Error.new("Value to generate \"#{@generate}\" does not match regular expression #{@matcher.inspect}") unless @generate =~ @matcher
|
31
32
|
end
|
32
33
|
|
33
34
|
def to_hash
|
34
|
-
{ json_class: self.class.name, data: { generate: generate, matcher: fix_regexp(matcher)} }
|
35
|
+
{ json_class: self.class.name, data: { generate: generate, matcher: fix_regexp(matcher) } }
|
35
36
|
end
|
36
37
|
|
37
38
|
def as_json(options = {})
|
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.16.
|
4
|
+
version: 1.16.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:
|
15
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: randexp
|
@@ -96,14 +96,14 @@ dependencies:
|
|
96
96
|
requirements:
|
97
97
|
- - "~>"
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
99
|
+
version: '13.0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
102
|
version_requirements: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
104
|
- - "~>"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
106
|
+
version: '13.0'
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
108
|
name: webmock
|
109
109
|
requirement: !ruby/object:Gem::Requirement
|
@@ -318,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
318
318
|
- !ruby/object:Gem::Version
|
319
319
|
version: '0'
|
320
320
|
requirements: []
|
321
|
-
rubygems_version: 3.
|
321
|
+
rubygems_version: 3.2.7
|
322
322
|
signing_key:
|
323
323
|
specification_version: 4
|
324
324
|
summary: Shared code for Pact gems
|