pact-support 1.20.2 → 1.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +66 -0
- data/lib/pact/generator/date.rb +62 -0
- data/lib/pact/generator/datetime.rb +16 -0
- data/lib/pact/generator/provider_state.rb +53 -0
- data/lib/pact/generator/random_boolean.rb +14 -0
- data/lib/pact/generator/random_decimal.rb +37 -0
- data/lib/pact/generator/random_hexadecimal.rb +19 -0
- data/lib/pact/generator/random_int.rb +16 -0
- data/lib/pact/generator/random_string.rb +16 -0
- data/lib/pact/generator/regex.rb +17 -0
- data/lib/pact/generator/time.rb +16 -0
- data/lib/pact/generator/uuid.rb +19 -0
- data/lib/pact/generators.rb +64 -0
- data/lib/pact/helpers.rb +10 -0
- data/lib/pact/matchers/matchers.rb +7 -1
- data/lib/pact/matchers/unix_diff_formatter.rb +2 -0
- data/lib/pact/shared/jruby_support.rb +9 -0
- data/lib/pact/support/version.rb +1 -1
- data/lib/pact/term.rb +5 -1
- metadata +43 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff89b1f300df93010c7b5820db53c8433fb8793ed895e8671c59b594f28008e4
|
4
|
+
data.tar.gz: 192212e7600f9c1be43e3817b479d59293582ad324e32262513a8db4982d850d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9335620e66ea4d6227973a7c2ca94f10bded7f05f9cdc8621715960619fcbde63e8d02d84c418027a4bde925d02dbc547641f8a73a34cb4269611016c0044f7
|
7
|
+
data.tar.gz: db26dea284a359a2c0b8a4e7db2a1dac2c488f228de11e2277ca4d154b342bf1338a5b574bab9326e46e05b8a0f6c21c19f2ef1899b62811f23b057ba4d57808
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
<a name="v1.21.0"></a>
|
2
|
+
### v1.21.0 (2024-11-28)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* add like_integer / like_decimal helpers ([75a36cd](/../../commit/75a36cd))
|
7
|
+
* add v3/v4 generators (thanks @slt) ([fe04975](/../../commit/fe04975))
|
8
|
+
|
9
|
+
#### Bug Fixes
|
10
|
+
|
11
|
+
* add blank lines to empty hashs - json 2.8.x regression ([66910bd](/../../commit/66910bd))
|
12
|
+
|
1
13
|
<a name="v1.20.2"></a>
|
2
14
|
### v1.20.2 (2024-10-23)
|
3
15
|
|
data/README.md
CHANGED
@@ -4,3 +4,69 @@
|
|
4
4
|
[![Join the chat at https://pact-foundation.slack.com/](https://img.shields.io/badge/chat-on%20slack-blue.svg?logo=slack)](https://slack.pact.io)
|
5
5
|
|
6
6
|
Provides shared code for the Pact gems
|
7
|
+
|
8
|
+
## Compatibility
|
9
|
+
|
10
|
+
<details><summary>Specification Compatibility</summary>
|
11
|
+
|
12
|
+
| Version | Stable | [Spec] Compatibility |
|
13
|
+
| ------- | ------ | -------------------- |
|
14
|
+
| 1.x.x | Yes | 2, 3\* |
|
15
|
+
|
16
|
+
_\*_ v3 support is limited to the subset of functionality required to enable language inter-operable [Message support].
|
17
|
+
|
18
|
+
- See V3 tracking [issue](https://github.com/pact-foundation/pact-ruby/issues/318).
|
19
|
+
- See V4 tracking [issue](https://github.com/pact-foundation/pact-ruby/issues/319).
|
20
|
+
|
21
|
+
Want V3/V4 support now? See the new standalone [pact-verifier](https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_verifier_cli#standalone-pact-verifier)
|
22
|
+
|
23
|
+
[message support]: https://github.com/pact-foundation/pact-specification/tree/version-3#introduces-messages-for-services-that-communicate-via-event-streams-and-message-queues
|
24
|
+
|
25
|
+
</details>
|
26
|
+
|
27
|
+
### Supported matching rules
|
28
|
+
|
29
|
+
| matcher | Spec Version | Implemented | Usage|
|
30
|
+
|---------------|--------------|-------------|-------------|
|
31
|
+
| Equality | V1 | | |
|
32
|
+
| Regex | V2 | ✅ | `Pact.term(generate, matcher)` |
|
33
|
+
| Type | V2 | ✅ | `Pact.like(generate)` |
|
34
|
+
| MinType | V2 | ✅ | `Pact.each_like(generate, min: <val>)` |
|
35
|
+
| MaxType | V2 | | |
|
36
|
+
| MinMaxType | V2 | | |
|
37
|
+
| Include | V3 | | |
|
38
|
+
| Integer | V3 | | |
|
39
|
+
| Decimal | V3 | | |
|
40
|
+
| Number | V3 | | |
|
41
|
+
| Timestamp | V3 | | |
|
42
|
+
| Time | V3 | | |
|
43
|
+
| Date | V3 | | |
|
44
|
+
| Null | V3 | | |
|
45
|
+
| Boolean | V3 | | |
|
46
|
+
| ContentType | V3 | | |
|
47
|
+
| Values | V3 | | |
|
48
|
+
| ArrayContains | V4 | | |
|
49
|
+
| StatusCode | V4 | | |
|
50
|
+
| NotEmpty | V4 | | |
|
51
|
+
| Semver | V4 | | |
|
52
|
+
| EachKey | V4 | | |
|
53
|
+
| EachValue | V4 | | |
|
54
|
+
|
55
|
+
### Supported generators
|
56
|
+
|
57
|
+
Currently limited to provider verification only. No current way to set in consumer tests.
|
58
|
+
|
59
|
+
| Generator | Spec Version | Implemented |
|
60
|
+
|------------------------|--------------|----|
|
61
|
+
| RandomInt | V3 | ✅ |
|
62
|
+
| RandomDecimal | V3 | ✅ |
|
63
|
+
| RandomHexadecimal | V3 | ✅ |
|
64
|
+
| RandomString | V3 | ✅ |
|
65
|
+
| Regex | V3 | ✅ |
|
66
|
+
| Uuid | V3/V4 | ✅ |
|
67
|
+
| Date | V3 | ✅ |
|
68
|
+
| Time | V3 | ✅ |
|
69
|
+
| DateTime | V3 | ✅ |
|
70
|
+
| RandomBoolean | V3 | ✅ |
|
71
|
+
| ProviderState | V4 | ✅ |
|
72
|
+
| MockServerURL | V4 | 🚧 |
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Generator
|
5
|
+
# Date provides the time generator which will give the current date in the defined format
|
6
|
+
class Date
|
7
|
+
def can_generate?(hash)
|
8
|
+
hash.key?('type') && hash['type'] == type
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(hash, _params = nil, _example_value = nil)
|
12
|
+
format = hash['format'] || default_format
|
13
|
+
::Time.now.strftime(convert_from_java_simple_date_format(format))
|
14
|
+
end
|
15
|
+
|
16
|
+
def type
|
17
|
+
'Date'
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_format
|
21
|
+
'yyyy-MM-dd'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Format for the pact specficiation should be the Java DateTimeFormmater
|
25
|
+
# This tries to convert to something Ruby can format.
|
26
|
+
def convert_from_java_simple_date_format(format)
|
27
|
+
# Year
|
28
|
+
format.sub!(/(?<!%)y{4,}/, '%Y')
|
29
|
+
format.sub!(/(?<!%)y{1,}/, '%y')
|
30
|
+
|
31
|
+
# Month
|
32
|
+
format.sub!(/(?<!%)M{4,}/, '%B')
|
33
|
+
format.sub!(/(?<!%)M{3}/, '%b')
|
34
|
+
format.sub!(/(?<!%)M{1,2}/, '%m')
|
35
|
+
|
36
|
+
# Week
|
37
|
+
format.sub!(/(?<!%)M{1,}/, '%W')
|
38
|
+
|
39
|
+
# Day
|
40
|
+
format.sub!(/(?<!%)D{1,}/, '%j')
|
41
|
+
format.sub!(/(?<!%)d{1,}/, '%d')
|
42
|
+
format.sub!(/(?<!%)E{4,}/, '%A')
|
43
|
+
format.sub!(/(?<!%)D{1,}/, '%a')
|
44
|
+
format.sub!(/(?<!%)u{1,}/, '%u')
|
45
|
+
|
46
|
+
# Time
|
47
|
+
format.sub!(/(?<!%)a{1,}/, '%p')
|
48
|
+
format.sub!(/(?<!%)k{1,}/, '%H')
|
49
|
+
format.sub!(/(?<!%)n{1,}/, '%M')
|
50
|
+
format.sub!(/(?<!%)s{1,}/, '%S')
|
51
|
+
format.sub!(/(?<!%)S{1,}/, '%L')
|
52
|
+
|
53
|
+
# Timezone
|
54
|
+
format.sub!(/(?<!%)z{1,}/, '%z')
|
55
|
+
format.sub!(/(?<!%)Z{1,}/, '%z')
|
56
|
+
format.sub!(/(?<!%)X{1,}/, '%Z')
|
57
|
+
|
58
|
+
format
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Generator
|
5
|
+
# DateTime provides the time generator which will give the current date time in the defined format
|
6
|
+
class DateTime < Date
|
7
|
+
def type
|
8
|
+
'DateTime'
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_format
|
12
|
+
'yyyy-MM-dd HH:mm'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'pact/logging'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Generator
|
5
|
+
# ProviderState provides the provider state generator which will inject
|
6
|
+
# values provided by the provider state setup url.
|
7
|
+
class ProviderState
|
8
|
+
include Pact::Logging
|
9
|
+
|
10
|
+
# rewrite of https://github.com/DiUS/pact-jvm/blob/master/core/support/src/main/kotlin/au/com/dius/pact/core/support/expressions/ExpressionParser.kt#L27
|
11
|
+
VALUES_SEPARATOR = ','
|
12
|
+
START_EXPRESSION = "\${"
|
13
|
+
END_EXPRESSION = '}'
|
14
|
+
|
15
|
+
def can_generate?(hash)
|
16
|
+
hash.key?('type') && hash['type'] == 'ProviderState'
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(hash, params = nil, _example_value = nil)
|
20
|
+
params ||= {}
|
21
|
+
parse_expression hash['expression'], params
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_expression(expression, params)
|
25
|
+
return_string = []
|
26
|
+
buffer = expression
|
27
|
+
# initial value
|
28
|
+
position = buffer.index(START_EXPRESSION)
|
29
|
+
|
30
|
+
while position && position >= 0
|
31
|
+
if position.positive?
|
32
|
+
# add string
|
33
|
+
return_string.push(buffer[0...position])
|
34
|
+
end
|
35
|
+
end_position = buffer.index(END_EXPRESSION, position)
|
36
|
+
raise 'Missing closing brace in expression string' if !end_position || end_position.negative?
|
37
|
+
|
38
|
+
variable = buffer[position + 2...end_position]
|
39
|
+
|
40
|
+
logger.info "Could not subsitute provider state key #{variable}, have #{params}" unless params[variable]
|
41
|
+
|
42
|
+
expression = params[variable] || ''
|
43
|
+
return_string.push(expression)
|
44
|
+
|
45
|
+
buffer = buffer[end_position + 1...-1]
|
46
|
+
position = buffer.index(START_EXPRESSION)
|
47
|
+
end
|
48
|
+
|
49
|
+
return_string.join('')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Pact
|
2
|
+
module Generator
|
3
|
+
# Boolean provides the boolean generator which will give a true or false value
|
4
|
+
class RandomBoolean
|
5
|
+
def can_generate?(hash)
|
6
|
+
hash.key?('type') && hash['type'] == 'RandomBoolean'
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(_hash, _params = nil, _example_value = nil)
|
10
|
+
[true, false].sample
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Generator
|
5
|
+
# RandomDecimal provides the random decimal generator which will generate a decimal value of digits length
|
6
|
+
class RandomDecimal
|
7
|
+
def can_generate?(hash)
|
8
|
+
hash.key?('type') && hash['type'] == 'RandomDecimal'
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(hash, _params = nil, _example_value = nil)
|
12
|
+
digits = hash['digits'] || 6
|
13
|
+
|
14
|
+
raise 'RandomDecimalGenerator digits must be > 0, got $digits' if digits < 1
|
15
|
+
|
16
|
+
return rand(0..9) if digits == 1
|
17
|
+
|
18
|
+
return rand(0..9) + rand(1..9) / 10 if digits == 2
|
19
|
+
|
20
|
+
pos = rand(1..digits - 1)
|
21
|
+
precision = digits - pos
|
22
|
+
integers = ''
|
23
|
+
decimals = ''
|
24
|
+
while pos.positive?
|
25
|
+
integers += String(rand(1..9))
|
26
|
+
pos -= 1
|
27
|
+
end
|
28
|
+
while precision.positive?
|
29
|
+
decimals += String(rand(1..9))
|
30
|
+
precision -= 1
|
31
|
+
end
|
32
|
+
|
33
|
+
Float("#{integers}.#{decimals}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Generator
|
5
|
+
# RandomHexadecimal provides the random hexadecimal generator which will generate a hexadecimal
|
6
|
+
class RandomHexadecimal
|
7
|
+
def can_generate?(hash)
|
8
|
+
hash.key?('type') && hash['type'] == 'RandomHexadecimal'
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(hash, _params = nil, _example_value = nil)
|
12
|
+
digits = hash['digits'] || 8
|
13
|
+
bytes = (digits / 2).ceil
|
14
|
+
string = SecureRandom.hex(bytes)
|
15
|
+
string[0, digits]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Pact
|
2
|
+
module Generator
|
3
|
+
# RandomInt provides the random int generator which generate a random integer, with a min/max
|
4
|
+
class RandomInt
|
5
|
+
def can_generate?(hash)
|
6
|
+
hash.key?('type') && hash['type'] == 'RandomInt'
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(hash, _params = nil, _example_value = nil)
|
10
|
+
min = hash['min'] || 0
|
11
|
+
max = hash['max'] || 2_147_483_647
|
12
|
+
rand(min..max)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Pact
|
2
|
+
module Generator
|
3
|
+
# RandomString provides the random string generator which generate a random string of size length
|
4
|
+
class RandomString
|
5
|
+
def can_generate?(hash)
|
6
|
+
hash.key?('type') && hash['type'] == 'RandomString'
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(hash, _params = nil, _example_value = nil)
|
10
|
+
size = hash['size'] || 20
|
11
|
+
string = rand(36**(size + 2)).to_s(36)
|
12
|
+
string[0, size]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'string_pattern'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Generator
|
5
|
+
# Regex provides the regex generator which will generate a value based on the regex pattern provided
|
6
|
+
class Regex
|
7
|
+
def can_generate?(hash)
|
8
|
+
hash.key?('type') && hash['type'] == 'Regex'
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(hash, _params = nil, _example_value = nil)
|
12
|
+
pattern = hash['pattern'] || ''
|
13
|
+
StringPattern.generate(Regexp.new(pattern))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Generator
|
5
|
+
# Time provides the time generator which will give the current time in the defined format
|
6
|
+
class Time < Date
|
7
|
+
def type
|
8
|
+
'Time'
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_format
|
12
|
+
'HH:mm'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
module Generator
|
5
|
+
# Uuid provides the uuid generator
|
6
|
+
class Uuid
|
7
|
+
def can_generate?(hash)
|
8
|
+
hash.key?('type') && hash['type'] == 'Uuid'
|
9
|
+
end
|
10
|
+
|
11
|
+
# If we had the example value, we could determine what type of uuid
|
12
|
+
# to send, this is what pact-jvm does
|
13
|
+
# See https://github.com/pact-foundation/pact-jvm/blob/master/core/model/src/main/kotlin/au/com/dius/pact/core/model/generators/Generator.kt
|
14
|
+
def call(_hash, _params = nil, _example_value = nil)
|
15
|
+
SecureRandom.uuid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'pact/generator/random_boolean'
|
2
|
+
require 'pact/generator/date'
|
3
|
+
require 'pact/generator/datetime'
|
4
|
+
require 'pact/generator/provider_state'
|
5
|
+
require 'pact/generator/random_decimal'
|
6
|
+
require 'pact/generator/random_hexadecimal'
|
7
|
+
require 'pact/generator/random_int'
|
8
|
+
require 'pact/generator/random_string'
|
9
|
+
require 'pact/generator/regex'
|
10
|
+
require 'pact/generator/time'
|
11
|
+
require 'pact/generator/uuid'
|
12
|
+
require 'pact/matching_rules/jsonpath'
|
13
|
+
require 'pact/matching_rules/v3/extract'
|
14
|
+
require 'jsonpath'
|
15
|
+
|
16
|
+
module Pact
|
17
|
+
class Generators
|
18
|
+
def self.add_generator(generator)
|
19
|
+
generators.unshift(generator)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.generators
|
23
|
+
@generators ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.execute_generators(object, state_params = nil, example_value = nil)
|
27
|
+
generators.each do |parser|
|
28
|
+
return parser.call(object, state_params, example_value) if parser.can_generate?(object)
|
29
|
+
end
|
30
|
+
|
31
|
+
raise Pact::UnrecognizePactFormatError, "This document does not use a recognised Pact generator: #{object}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.apply_generators(expected_request, component, example_value, state_params)
|
35
|
+
# Latest pact-support is required to have generators exposed
|
36
|
+
if expected_request.methods.include?(:generators) && expected_request.generators[component]
|
37
|
+
# Some component will have single generator without selectors, i.e. path
|
38
|
+
generators = expected_request.generators[component]
|
39
|
+
if generators.is_a?(Hash) && generators.key?('type')
|
40
|
+
return execute_generators(generators, state_params, example_value)
|
41
|
+
end
|
42
|
+
|
43
|
+
generators.each do |selector, generator|
|
44
|
+
val = JsonPath.new(selector).on(example_value)
|
45
|
+
replace = execute_generators(generator, state_params, val)
|
46
|
+
example_value = JsonPath.for(example_value).gsub(selector) { |_v| replace }.to_hash
|
47
|
+
end
|
48
|
+
end
|
49
|
+
example_value
|
50
|
+
end
|
51
|
+
|
52
|
+
add_generator(Generator::RandomBoolean.new)
|
53
|
+
add_generator(Generator::Date.new)
|
54
|
+
add_generator(Generator::DateTime.new)
|
55
|
+
add_generator(Generator::ProviderState.new)
|
56
|
+
add_generator(Generator::RandomDecimal.new)
|
57
|
+
add_generator(Generator::RandomHexadecimal.new)
|
58
|
+
add_generator(Generator::RandomInt.new)
|
59
|
+
add_generator(Generator::RandomString.new)
|
60
|
+
add_generator(Generator::Regex.new)
|
61
|
+
add_generator(Generator::Time.new)
|
62
|
+
add_generator(Generator::Uuid.new)
|
63
|
+
end
|
64
|
+
end
|
data/lib/pact/helpers.rb
CHANGED
@@ -47,6 +47,16 @@ module Pact
|
|
47
47
|
Pact::Term.new(generate: date, matcher: /^\d{4}-[01]\d-[0-3]\d$/)
|
48
48
|
end
|
49
49
|
|
50
|
+
# regex matched with pact-jvm
|
51
|
+
# https://github.com/pact-foundation/pact-jvm/blob/00442e6df51e5be906ed470b19859246312e5c83/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/MatcherExecutor.kt#L56-L59
|
52
|
+
def like_integer int
|
53
|
+
Pact::Term.new(generate: int, matcher: /^-?\d+$/)
|
54
|
+
end
|
55
|
+
|
56
|
+
def like_decimal float
|
57
|
+
Pact::Term.new(generate: float, matcher: /^0|-?\d+\.\d*$/)
|
58
|
+
end
|
59
|
+
|
50
60
|
def like_datetime_rfc822 datetime
|
51
61
|
Pact::Term.new(
|
52
62
|
generate: datetime,
|
@@ -61,6 +61,12 @@ module Pact
|
|
61
61
|
alias_method :structure_diff, :type_diff # Backwards compatibility
|
62
62
|
|
63
63
|
def term_diff term, actual, options
|
64
|
+
if actual.is_a?(Float) || actual.is_a?(Integer)
|
65
|
+
options[:original] = actual
|
66
|
+
options[:was_float] = actual.is_a?(Float)
|
67
|
+
options[:was_int] = actual.is_a?(Integer)
|
68
|
+
actual = actual.to_s
|
69
|
+
end
|
64
70
|
if actual.is_a?(String)
|
65
71
|
actual_term_diff term, actual, options
|
66
72
|
else
|
@@ -72,7 +78,7 @@ module Pact
|
|
72
78
|
if term.matcher.match(actual)
|
73
79
|
NO_DIFF
|
74
80
|
else
|
75
|
-
RegexpDifference.new term.matcher, actual, "Expected a
|
81
|
+
RegexpDifference.new term.matcher, options[:original] ||= actual, "Expected a Value matching #{term.matcher.inspect} (like #{term.generate.inspect}) but got #{options[:was_float] || options[:was_int] ? class_name_with_value_in_brackets(options[:original]) : actual.inspect} at <path>"
|
76
82
|
end
|
77
83
|
end
|
78
84
|
|
@@ -62,6 +62,8 @@ module Pact
|
|
62
62
|
begin
|
63
63
|
# Can't think of an elegant way to check if we can pretty generate other than to try it and maybe fail
|
64
64
|
json = fix_blank_lines_in_empty_hashes JSON.pretty_generate(comparable)
|
65
|
+
json = add_blank_lines_in_empty_hashes json
|
66
|
+
json = add_blank_lines_in_empty_arrays json
|
65
67
|
add_comma_to_end_of_arrays json
|
66
68
|
rescue JSON::GeneratorError
|
67
69
|
comparable.to_s
|
@@ -14,5 +14,14 @@ module Pact
|
|
14
14
|
json.gsub(/({\n)\n(\s*})/,'\1\2')
|
15
15
|
end
|
16
16
|
|
17
|
+
# preserve pre json 2.8.x behaviour
|
18
|
+
# https://github.com/ruby/json/pull/626
|
19
|
+
def add_blank_lines_in_empty_hashes(json)
|
20
|
+
json.gsub(/({\s*})/, "{\n }")
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_blank_lines_in_empty_arrays(json)
|
24
|
+
json.gsub(/\[\s*\]/, "[\n ]")
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
data/lib/pact/support/version.rb
CHANGED
data/lib/pact/term.rb
CHANGED
@@ -29,7 +29,11 @@ module Pact
|
|
29
29
|
@matcher = attributes[:matcher]
|
30
30
|
raise Pact::Error.new("Please specify a matcher for the Term") unless @matcher != nil
|
31
31
|
raise Pact::Error.new("Please specify a value to generate for the Term") unless @generate != nil
|
32
|
-
|
32
|
+
if @generate.is_a?(Float) || @generate.is_a?(Integer)
|
33
|
+
raise Pact::Error.new("#{@generate.is_a?(Float) ? "Float" : "Integer"} Value to generate '#{@generate}' does not match regular expression #{@matcher.inspect} when converted to string") unless @generate.to_s =~ @matcher
|
34
|
+
else
|
35
|
+
raise Pact::Error.new("Value to generate '#{@generate}' does not match regular expression #{@matcher.inspect}") unless @generate =~ @matcher
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
def to_hash
|
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.
|
4
|
+
version: 1.21.0
|
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: 2024-
|
15
|
+
date: 2024-11-29 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rainbow
|
@@ -70,6 +70,34 @@ dependencies:
|
|
70
70
|
- - "~>"
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0.1'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: string_pattern
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '2.0'
|
80
|
+
type: :runtime
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - "~>"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '2.0'
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: jsonpath
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.0'
|
94
|
+
type: :runtime
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '1.0'
|
73
101
|
- !ruby/object:Gem::Dependency
|
74
102
|
name: rspec
|
75
103
|
requirement: !ruby/object:Gem::Requirement
|
@@ -281,6 +309,18 @@ files:
|
|
281
309
|
- lib/pact/consumer_contract/service_provider.rb
|
282
310
|
- lib/pact/consumer_contract/string_with_matching_rules.rb
|
283
311
|
- lib/pact/errors.rb
|
312
|
+
- lib/pact/generator/date.rb
|
313
|
+
- lib/pact/generator/datetime.rb
|
314
|
+
- lib/pact/generator/provider_state.rb
|
315
|
+
- lib/pact/generator/random_boolean.rb
|
316
|
+
- lib/pact/generator/random_decimal.rb
|
317
|
+
- lib/pact/generator/random_hexadecimal.rb
|
318
|
+
- lib/pact/generator/random_int.rb
|
319
|
+
- lib/pact/generator/random_string.rb
|
320
|
+
- lib/pact/generator/regex.rb
|
321
|
+
- lib/pact/generator/time.rb
|
322
|
+
- lib/pact/generator/uuid.rb
|
323
|
+
- lib/pact/generators.rb
|
284
324
|
- lib/pact/helpers.rb
|
285
325
|
- lib/pact/http/authorization_header_redactor.rb
|
286
326
|
- lib/pact/logging.rb
|
@@ -347,7 +387,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
347
387
|
- !ruby/object:Gem::Version
|
348
388
|
version: '0'
|
349
389
|
requirements: []
|
350
|
-
rubygems_version: 3.5.
|
390
|
+
rubygems_version: 3.5.23
|
351
391
|
signing_key:
|
352
392
|
specification_version: 4
|
353
393
|
summary: Shared code for Pact gems
|