Module: Pact::Matchers

Included in:
PactConsumerDsl
Defined in:
lib/pact/matchers.rb,
lib/pact/matchers/base.rb,
lib/pact/matchers/v2/type.rb,
lib/pact/matchers/v3/date.rb,
lib/pact/matchers/v3/each.rb,
lib/pact/matchers/v3/null.rb,
lib/pact/matchers/v3/time.rb,
lib/pact/matchers/v2/regex.rb,
lib/pact/matchers/v3/number.rb,
lib/pact/matchers/v3/semver.rb,
lib/pact/matchers/v3/values.rb,
lib/pact/matchers/v3/boolean.rb,
lib/pact/matchers/v3/decimal.rb,
lib/pact/matchers/v3/include.rb,
lib/pact/matchers/v3/integer.rb,
lib/pact/matchers/v1/equality.rb,
lib/pact/matchers/v4/each_key.rb,
lib/pact/matchers/v3/date_time.rb,
lib/pact/matchers/v4/not_empty.rb,
lib/pact/matchers/v4/each_value.rb,
lib/pact/matchers/v4/status_code.rb,
lib/pact/matchers/v3/content_type.rb,
lib/pact/matchers/v4/each_key_value.rb

Defined Under Namespace

Modules: V1, V2, V3, V4 Classes: Base

Constant Summary collapse

PACT_SPEC_V1 =
1
PACT_SPEC_V2 =
2
PACT_SPEC_V3 =
3
PACT_SPEC_V4 =
4
ANY_STRING_REGEX =
/.*/
UUID_REGEX =
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i
ISO8601_REGEX =

simplified

/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)*(.\d{2}:\d{2})*/i

Instance Method Summary collapse

Instance Method Details

#match_any_boolean(sample = true) ⇒ Object



44
45
46
# File 'lib/pact/matchers.rb', line 44

def match_any_boolean(sample = true)
  V3::Boolean.new(sample)
end

#match_any_decimal(sample = 10.0) ⇒ Object



36
37
38
# File 'lib/pact/matchers.rb', line 36

def match_any_decimal(sample = 10.0)
  V3::Decimal.new(sample)
end

#match_any_integer(sample = 10) ⇒ Object



32
33
34
# File 'lib/pact/matchers.rb', line 32

def match_any_integer(sample = 10)
  V3::Integer.new(sample)
end

#match_any_number(sample = 10.0) ⇒ Object



40
41
42
# File 'lib/pact/matchers.rb', line 40

def match_any_number(sample = 10.0)
  V3::Number.new(sample)
end

#match_any_string(sample = "any") ⇒ Object



28
29
30
# File 'lib/pact/matchers.rb', line 28

def match_any_string(sample = "any")
  V2::Regex.new(ANY_STRING_REGEX, sample)
end

#match_content_type(content_type, template = nil) ⇒ Object



96
97
98
# File 'lib/pact/matchers.rb', line 96

def match_content_type(content_type, template = nil)
  V3::ContentType.new(content_type, template: template)
end

#match_date(format, sample) ⇒ Object



64
65
66
# File 'lib/pact/matchers.rb', line 64

def match_date(format, sample)
  V3::Date.new(format, sample)
end

#match_datetime(format, sample) ⇒ Object



56
57
58
# File 'lib/pact/matchers.rb', line 56

def match_datetime(format, sample)
  V3::DateTime.new(format, sample)
end

#match_each(template, min = nil) ⇒ Object



72
73
74
# File 'lib/pact/matchers.rb', line 72

def match_each(template, min = nil)
  V3::Each.new(template, min)
end

#match_each_key(template, key_matchers) ⇒ Object



80
81
82
# File 'lib/pact/matchers.rb', line 80

def match_each_key(template, key_matchers)
  V4::EachKey.new(key_matchers.is_a?(Array) ? key_matchers : [key_matchers], template)
end

#match_each_kv(template, key_matchers) ⇒ Object



88
89
90
# File 'lib/pact/matchers.rb', line 88

def match_each_kv(template, key_matchers)
  V4::EachKeyValue.new(key_matchers.is_a?(Array) ? key_matchers : [key_matchers], template)
end

#match_each_regex(regex, sample) ⇒ Object



76
77
78
# File 'lib/pact/matchers.rb', line 76

def match_each_regex(regex, sample)
  match_each_value(sample, match_regex(regex, sample))
end

#match_each_value(template, value_matchers = V2::Type.new("")) ⇒ Object



84
85
86
# File 'lib/pact/matchers.rb', line 84

def match_each_value(template, value_matchers = V2::Type.new(""))
  V4::EachValue.new(value_matchers.is_a?(Array) ? value_matchers : [value_matchers], template)
end

#match_exactly(arg) ⇒ Object



16
17
18
# File 'lib/pact/matchers.rb', line 16

def match_exactly(arg)
  V1::Equality.new(arg)
end

#match_include(arg) ⇒ Object



24
25
26
# File 'lib/pact/matchers.rb', line 24

def match_include(arg)
  V3::Include.new(arg)
end

#match_iso8601(sample = "2024-08-12T12:25:00.243118+03:00") ⇒ Object



60
61
62
# File 'lib/pact/matchers.rb', line 60

def match_iso8601(sample = "2024-08-12T12:25:00.243118+03:00")
  V2::Regex.new(ISO8601_REGEX, sample)
end

#match_not_empty(template = nil) ⇒ Object



100
101
102
# File 'lib/pact/matchers.rb', line 100

def match_not_empty(template = nil)
  V4::NotEmpty.new(template)
end

#match_regex(regex, sample) ⇒ Object



52
53
54
# File 'lib/pact/matchers.rb', line 52

def match_regex(regex, sample)
  V2::Regex.new(regex, sample)
end

#match_semver(template = nil) ⇒ Object



92
93
94
# File 'lib/pact/matchers.rb', line 92

def match_semver(template = nil)
  V3::Semver.new(template)
end

#match_status_code(template) ⇒ Object



104
105
106
# File 'lib/pact/matchers.rb', line 104

def match_status_code(template)
  V4::StatusCode.new(template)
end

#match_time(format, sample) ⇒ Object



68
69
70
# File 'lib/pact/matchers.rb', line 68

def match_time(format, sample)
  V3::Time.new(format, sample)
end

#match_type_of(arg) ⇒ Object



20
21
22
# File 'lib/pact/matchers.rb', line 20

def match_type_of(arg)
  V2::Type.new(arg)
end

#match_uuid(sample = "e1d01e04-3a2b-4eed-a4fb-54f5cd257338") ⇒ Object



48
49
50
# File 'lib/pact/matchers.rb', line 48

def match_uuid(sample = "e1d01e04-3a2b-4eed-a4fb-54f5cd257338")
  V2::Regex.new(UUID_REGEX, sample)
end