Skip to content

Conversation

YOU54F
Copy link
Member

@YOU54F YOU54F commented Sep 11, 2025

We would like to implement Pact V3 Specification support for Pact Ruby

Pact Ruby V2

Fixes #317, #318, #319

Documentation

https://github.com/pact-foundation/pact-ruby/blob/feat/v2/documentation/README_V2.md

Delivered Features

  • Multiple specification support 1️⃣ 2️⃣ 3️⃣ 4️⃣
  • Multiple interaction types
    • ✅ Synchronous/HTTP
    • ✅ Asynchronous/Message
    • 🚧 Synchronous/Message
  • Pact Plugin support
    • ✅ gRPC
    • 🚧 Generic
  • Matchers
    • See below list
  • Generators
    • See below list

Validation

The following projects were designed for pact-ruby-v1 and have been migrated to pact-ruby-v2. They can serve as an example of the work required.

V3 Related Issues

Will be tagging and closing related v3/v4 issues, and linking to this meta issue

V4 Related Issues

Will be tagging and closing related v3/v4 issues, and linking to this meta issue

V3 Generators

todo - complete list of delivered generators / matchers

Generator Attributes Description Example JSON
RandomInt min, max Generates a random integer value between min and max values { "type": "RandomInt", "min": 0, "max": 2147483647 }
RandomDecimal digits Generates a random decimal value (BigDecimal) with the provided number of digits { "type": "RandomDecimal", "digits": 6 }
RandomHexadecimal digits Generates a random hexadecimal value (String) with the provided number of digits { "type": "RandomHexadecimal", "digits": 8 }
RandomString size Generates a random string value of the provided size characters { "type": "RandomString", "size": 20 }
Regex regex Generates a random string value from the provided regular expression { "type": "Regex", "regex": "\\d{1,8}" }
Uuid Generates a random UUID value (simple format) { "type": "Uuid" }
Date format (Optional) Generates a Date value from the current date either in ISO format or using the provided format string { "type": "Date", "format": "MM/dd/yyyy" }
Time format (Optional) Generates a Time value from the current time either in ISO format or using the provided format string { "type": "Time", "format": "HH:mm" }
DateTime format (Optional) Generates a Date and Time (timestamp) value from the current date and time either in ISO format or using the provided format string { "type": "DateTime", "format": "yyyy/MM/dd - HH:mm:ss.S" }
Boolean Generates a random boolean value { "type": "RandomBoolean" }

V3 Matchers

matcher Spec Version example configuration description
Include V3 { "match": "include", "value": "substr" } This checks if the string representation of a value contains the substring.
Integer V3 { "match": "integer" } This checks if the type of the value is an integer.
Decimal V3 { "match": "decimal" } This checks if the type of the value is a number with decimal places.
Number V3 { "match": "number" } This checks if the type of the value is a number.
Timestamp V3 { "match": "datetime", "format": "yyyy-MM-dd HH:ss:mm" } Matches the string representation of a value against the datetime format
Time V3 { "match": "time", "format": "HH:ss:mm" } Matches the string representation of a value against the time format
Date V3 { "match": "date", "format": "yyyy-MM-dd" } Matches the string representation of a value against the date format
Null V3 { "match": "null" } Match if the value is a null value (this is content specific, for JSON will match a JSON null)
Boolean V3 { "match": "boolean" } Match if the value is a boolean value (booleans and the string values true and false)
ContentType V3 { "match": "contentType", "value": "image/jpeg" } Match binary data by its content type (magic file check)
Values V3 { "match": "values" } Match the values in a map, ignoring the keys

V4 Matchers

matcher Spec Version example configuration description
ArrayContains V4 { "match": "arrayContains", "variants": [...] } Checks if all the variants are present in an array.
StatusCode V4 { "match": "statusCode", "status": "success" } Matches the response status code.
NotEmpty V4 { "match": "notEmpty" } Value must be present and not empty (not null or the empty string)
Semver V4 { "match": "semver" } Value must be valid based on the semver specification
EachKey V4 { "match": "eachKey", "rules": [{"match": "regex", "regex": "\\$(\\.\\w+)+"}], "value": "$.test.one" } Allows defining matching rules to apply to the keys in a map
EachValue V4 { "match": "eachValue", "rules": [{"match": "regex", "regex": "\\$(\\.\\w+)+"}], "value": "$.test.one" } Allows defining matching rules to apply to the values in a collection. For maps, delgates to the Values matcher.

V4 Generators

matcher Spec Version example configuration description
ProviderState V4 {"expression": "/api/user/${id}", type": "ProviderState"} Generates a value that is looked up from the provider state context using the given expression
MockServerURL V4 {"regex": ".*\\/(orders\\/\\d+)$", "example": "http://localhost:1234/orders/5678", type": "MockServerURL"} Generates a URL with the mock server as the base URL.

@YOU54F
Copy link
Member Author

YOU54F commented Sep 23, 2025

This is published as a test gem to

https://rubygems.org/gems/pact-v2

there are two versions. the first contains only the v1 deps, the second contains both v1 & v2 deps.

It doesn’t seem rubygems supports conditional gems ( i wanted to control it by env var ) i did look at a ruby extension to install additional gems but these wouldn’t be known to bundler

the test gem will ultimately be deleted, so please don’t rely in production. ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pact FFI Tracking Issue
1 participant