From 8435f01519017acdc4b252fe37e26b61943be685 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 9 Nov 2026 17:31:22 +0000 Subject: [PATCH 1/5] feat(matchers): emit match_or/match_and as pact_ffi integration JSON Combined matchers now serialise inline, like every other matcher: {"pact:matcher:type":[], "pact:matcher:combine":"OR"|"AND","value":} This needs a pact_ffi with `pact:matcher:combine` support (pact-foundation/pact-reference#601), which writes the usual `{"combine":"OR","matchers":[...]}` rule list to the pact file. - Combined is now a Pact::Matchers::Base, so it is serialised wherever matchers are (request/response bodies, headers, query, message contents) and can be nested in a hash/array or inside another matcher's sample. - Matchers nested in an object sample keep their own rules, so null-or-object works. - Drop the separate PactFfi.with_matching_rules call, the path tracking in InteractionContents and Base#as_matching_rule. - A Combined cannot be an alternative of another Combined, and is rejected in plugin (matching(...)) contents. Co-Authored-By: Claude Opus 5.5 --- lib/pact/consumer/http_interaction_builder.rb | 38 +------- lib/pact/consumer/interaction_contents.rb | 42 +++++---- lib/pact/matchers.rb | 2 +- lib/pact/matchers/base.rb | 6 -- lib/pact/matchers/combined.rb | 46 +++++++--- .../lib/consumer/interaction_contents_spec.rb | 22 +++++ spec/lib/matchers_spec.rb | 88 ++++++++++++++++++- 7 files changed, 165 insertions(+), 79 deletions(-) diff --git a/lib/pact/consumer/http_interaction_builder.rb b/lib/pact/consumer/http_interaction_builder.rb index 62f76c5b..37782046 100644 --- a/lib/pact/consumer/http_interaction_builder.rb +++ b/lib/pact/consumer/http_interaction_builder.rb @@ -83,24 +83,7 @@ def with_request(method: nil, path: nil, query: {}, headers: {}, body: nil) end if body - contents = InteractionContents.basic(body) - - PactFfi.with_body( - pact_interaction, - interaction_part, - "application/json", - format_value(contents.value) - ) - - if contents.matching_rules.any? - PactFfi.with_matching_rules( - pact_interaction, - interaction_part, - JSON.dump( - "body" => contents.matching_rules - ) - ) - end + PactFfi.with_body(pact_interaction, interaction_part, "application/json", format_value(InteractionContents.basic(body).value)) end self @@ -123,24 +106,7 @@ def will_respond_with(status: nil, headers: {}, body: nil) end if body - contents = InteractionContents.basic(body) - - PactFfi.with_body( - pact_interaction, - interaction_part, - "application/json", - format_value(contents.value) - ) - - if contents.matching_rules.any? - PactFfi.with_matching_rules( - pact_interaction, - interaction_part, - JSON.dump( - "body" => contents.matching_rules - ) - ) - end + PactFfi.with_body(pact_interaction, interaction_part, "application/json", format_value(InteractionContents.basic(body).value)) end self diff --git a/lib/pact/consumer/interaction_contents.rb b/lib/pact/consumer/interaction_contents.rb index 0ec0d1fd..4303ba50 100644 --- a/lib/pact/consumer/interaction_contents.rb +++ b/lib/pact/consumer/interaction_contents.rb @@ -6,7 +6,7 @@ class InteractionContents < Hash BASIC_FORMAT = :basic PLUGIN_FORMAT = :plugin - attr_reader :format, :matching_rules + attr_reader :format def self.basic(contents_hash) new(contents_hash, BASIC_FORMAT) @@ -17,15 +17,14 @@ def self.plugin(contents_hash) end def initialize(contents_hash, format) - @matching_rules = {} - serialized = serialize(contents_hash.deep_dup, format, '$') - + serialized = init_hash(contents_hash, format) + # A scalar body (plain string, integer, etc.) serializes to a non-Hash + # value that cannot be merged pair by pair; expose it via #value instead. if serialized.is_a?(Hash) serialized.each_pair { |k, v| self[k] = v } else @value = serialized end - @format = format end @@ -35,29 +34,28 @@ def value private - def serialize(value, format, path) - if value.is_a?(Pact::Matchers::Combined) - @matching_rules[path] = value.as_matching_rule - return value.template + def serialize(hash, format) + # serialize recursively + if hash.is_a?(Pact::Matchers::Base) || hash.is_a?(Pact::Generators::Base) + return hash.as_basic if format == :basic + return hash.as_plugin if format == :plugin end - if value.is_a?(Pact::Matchers::Base) || - value.is_a?(Pact::Generators::Base) - return value.as_basic if format == :basic - return value.as_plugin if format == :plugin - end + return hash.map { |value| serialize(value, format) } if hash.is_a?(Array) - if value.is_a?(Array) - return value.each_with_index.map do |item, index| - serialize(item, format, "#{path}[#{index}]") - end + # A value that is not a collection or a matcher/generator has nothing to + # recurse into, so return it unchanged (string, integer, boolean, nil, ...). + return hash unless hash.is_a?(Hash) + + hash.each_pair do |key, value| + hash[key] = serialize(value, format) end - return value unless value.is_a?(Hash) + hash + end - value.each_with_object({}) do |(key, child), result| - result[key] = serialize(child, format, "#{path}.#{key}") - end + def init_hash(hash, format) + serialize(hash.deep_dup, format) end end end diff --git a/lib/pact/matchers.rb b/lib/pact/matchers.rb index d251fbc1..02c608f6 100644 --- a/lib/pact/matchers.rb +++ b/lib/pact/matchers.rb @@ -32,7 +32,7 @@ def match_null def match_or(*matchers, sample:) Combined.new(matchers, combine: :or, template: sample) end - + def match_and(*matchers, sample:) Combined.new(matchers, combine: :and, template: sample) end diff --git a/lib/pact/matchers/base.rb b/lib/pact/matchers/base.rb index 8bb90d16..afc142d9 100644 --- a/lib/pact/matchers/base.rb +++ b/lib/pact/matchers/base.rb @@ -38,12 +38,6 @@ def as_plugin "matching(#{@kind}, #{value})" end - def as_matching_rule - { - "match" => serialize!(@kind.deep_dup, :basic) - }.merge(serialize!(@opts.deep_dup, :basic)) - end - private def serialize!(data, format) diff --git a/lib/pact/matchers/combined.rb b/lib/pact/matchers/combined.rb index f1403e4a..79196acb 100644 --- a/lib/pact/matchers/combined.rb +++ b/lib/pact/matchers/combined.rb @@ -1,32 +1,52 @@ +# frozen_string_literal: true + module Pact module Matchers - class Combined + # Applies several matchers to the same path, combined with AND or OR logic. + # + # Serialises to pact_ffi integration JSON, with every matcher (without its + # example value) in the `pact:matcher:type` array and the sample as the + # single `value`: + # + # { + # "pact:matcher:type": [{"pact:matcher:type": "type"}, {"pact:matcher:type": "null"}], + # "pact:matcher:combine": "OR", + # "value": "Fred" + # } + # + # Requires a pact_ffi version that supports `pact:matcher:combine` + # (pact-foundation/pact-reference#601). + class Combined < Base VALID_COMBINATIONS = %i[and or].freeze - attr_reader :matchers, :combine, :template + attr_reader :matchers, :combine def initialize(matchers, combine:, template:) - raise ArgumentError, "At least two matchers are required" if matchers.size < 2 + raise ArgumentError, 'At least two matchers are required' if matchers.size < 2 - unless matchers.all?(Pact::Matchers::Base) - raise ArgumentError, "All values must be Pact matchers" + unless matchers.all? { |m| m.is_a?(Pact::Matchers::Base) && !m.is_a?(Combined) } + raise ArgumentError, 'All values must be Pact matchers' end - unless VALID_COMBINATIONS.include?(combine) - raise ArgumentError, "combine must be :and or :or" - end + raise ArgumentError, 'combine must be :and or :or' unless VALID_COMBINATIONS.include?(combine) @matchers = matchers @combine = combine - @template = template + super(spec_version: Pact::Matchers::PACT_SPEC_V3, kind: matchers.map(&:kind), template: template) end - def as_matching_rule + def as_basic { - "combine" => combine.to_s.upcase, - "matchers" => matchers.map(&:as_matching_rule) + 'pact:matcher:type' => matchers.map { |m| m.as_basic.except('value') }, + 'pact:matcher:combine' => combine.to_s.upcase, + 'value' => serialize!(template.deep_dup, :basic) } end + + def as_plugin + raise MatcherInitializationError, + "#{self.class}: combined (match_#{combine}) matchers are not supported in plugin contents" + end end end -end \ No newline at end of file +end diff --git a/spec/lib/consumer/interaction_contents_spec.rb b/spec/lib/consumer/interaction_contents_spec.rb index 686118dd..40930c85 100644 --- a/spec/lib/consumer/interaction_contents_spec.rb +++ b/spec/lib/consumer/interaction_contents_spec.rb @@ -46,4 +46,26 @@ expect(described_class.basic({ some_array: [42] }).to_json).to eq('{"some_array":[42]}') end end + + context 'with combined (OR) matchers' do + it 'serializes them inline as integration JSON at any depth' do + contents = { pet: { name: match_any_string_or_nil('Rex'), tags: [match_any_integer_or_nil(1)] } } + or_rule = lambda do |rule, value| + { 'pact:matcher:type' => [rule, { 'pact:matcher:type' => 'null' }], 'pact:matcher:combine' => 'OR', + 'value' => value } + end + + expect(JSON.parse(described_class.basic(contents).to_json)).to eq( + 'pet' => { + 'name' => or_rule.call({ 'pact:matcher:type' => 'regex', 'regex' => '(?-mix:.*)' }, 'Rex'), + 'tags' => [or_rule.call({ 'pact:matcher:type' => 'integer' }, 1)] + } + ) + end + + it 'serializes a top-level combined matcher (e.g. a header value)' do + expect(described_class.basic({ 'X-Id' => match_or(match_regex(/\d+/, '1'), match_null, sample: '1') })['X-Id']) + .to include('pact:matcher:combine' => 'OR', 'value' => '1') + end + end end diff --git a/spec/lib/matchers_spec.rb b/spec/lib/matchers_spec.rb index 5c3a6567..9da1fe38 100644 --- a/spec/lib/matchers_spec.rb +++ b/spec/lib/matchers_spec.rb @@ -58,7 +58,7 @@ let(:boolean_matcher) { test_class.match_any_boolean(true) } let(:null_matcher) { test_class.match_null } - it 'creates an OR combination of the provided matchers' do + it 'creates an AND combination of the provided matchers' do expect(matcher).to have_attributes( combine: :and, template: true, @@ -89,6 +89,92 @@ end end + context 'with combined matchers serialized to integration JSON' do + it 'serializes match_or with each matcher (without its value) and the sample as the value' do + matcher = test_class.match_or(test_class.match_type_of('Fred'), test_class.match_null, sample: 'Fred') + + expect(JSON.parse(matcher.as_basic.to_json)).to eq( + 'pact:matcher:type' => [{ 'pact:matcher:type' => 'type' }, { 'pact:matcher:type' => 'null' }], + 'pact:matcher:combine' => 'OR', + 'value' => 'Fred' + ) + end + + it 'serializes match_and with AND' do + matcher = test_class.match_and(test_class.match_regex(/\d+/, '12'), test_class.match_include('1'), sample: '12') + + expect(JSON.parse(matcher.as_basic.to_json)).to eq( + 'pact:matcher:type' => [ + { 'pact:matcher:type' => 'regex', 'regex' => '(?-mix:\d+)' }, + { 'pact:matcher:type' => 'include' } + ], + 'pact:matcher:combine' => 'AND', + 'value' => '12' + ) + end + + it 'keeps matcher attributes on each alternative' do + expect(JSON.parse(test_class.match_datetime_or_nil('yyyy-MM-dd', '2020-05-21').as_basic.to_json)).to eq( + 'pact:matcher:type' => [ + { 'pact:matcher:type' => 'datetime', 'format' => 'yyyy-MM-dd' }, + { 'pact:matcher:type' => 'null' } + ], + 'pact:matcher:combine' => 'OR', + 'value' => '2020-05-21' + ) + end + + it 'serializes nested matchers inside an object sample (null-or-object)' do + matcher = test_class.match_or( + test_class.match_type_of({}), test_class.match_null, + sample: { street: 'Main St', number: test_class.match_any_integer(42) } + ) + + expect(JSON.parse(matcher.as_basic.to_json)).to eq( + 'pact:matcher:type' => [{ 'pact:matcher:type' => 'type' }, { 'pact:matcher:type' => 'null' }], + 'pact:matcher:combine' => 'OR', + 'value' => { 'street' => 'Main St', 'number' => { 'pact:matcher:type' => 'integer', 'value' => 42 } } + ) + end + + it 'emits a null value when the sample is nil' do + matcher = test_class.match_or(test_class.match_null, test_class.match_any_integer(1), sample: nil) + + expect(matcher.as_basic).to include('value' => nil) + end + + { + match_any_string_or_nil: [['any'], { 'pact:matcher:type' => 'regex', 'regex' => '(?-mix:.*)' }, 'any'], + match_any_integer_or_nil: [[], { 'pact:matcher:type' => 'integer' }, 10], + match_any_decimal_or_nil: [[], { 'pact:matcher:type' => 'decimal' }, 10.0], + match_any_number_or_nil: [[], { 'pact:matcher:type' => 'number' }, 10.0], + match_any_boolean_or_nil: [[], { 'pact:matcher:type' => 'boolean' }, true], + match_date_or_nil: [%w[yyyy-MM-dd 2020-05-21], { 'pact:matcher:type' => 'date', 'format' => 'yyyy-MM-dd' }, + '2020-05-21'], + match_time_or_nil: [%w[HH:mm 16:44], { 'pact:matcher:type' => 'time', 'format' => 'HH:mm' }, '16:44'] + }.each do |helper, (args, first_rule, sample)| + it "#{helper} serializes to OR null" do + expect(JSON.parse(test_class.public_send(helper, *args).as_basic.to_json)).to eq( + 'pact:matcher:type' => [first_rule, { 'pact:matcher:type' => 'null' }], + 'pact:matcher:combine' => 'OR', + 'value' => sample + ) + end + end + + it 'rejects a combined matcher as an alternative' do + inner = test_class.match_any_string_or_nil('x') + + expect { test_class.match_or(inner, test_class.match_any_integer(1), sample: 'x') } + .to raise_error(ArgumentError, 'All values must be Pact matchers') + end + + it 'is not supported in plugin contents' do + expect { test_class.match_any_string_or_nil('x').as_plugin } + .to raise_error(Pact::Matchers::Base::MatcherInitializationError, /not supported in plugin contents/) + end + end + context 'with basic format serialization' do it 'properly builds matcher for null' do expect(test_class.match_null.as_basic).to eq({ From 220076112b796782ee1af7d4e00722c023f2dedd Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 9 Nov 2026 17:31:23 +0000 Subject: [PATCH 2/5] fix(consumer): release the mock server when an interaction has mismatches HttpInteractionBuilder#execute raised InteractionMismatchesError before cleaning up, so the mock server kept its port and the pact handle was not reset; the next interaction on the same port then failed with "Address already in use". It also raised NoMethodError, hiding the real error, when the mock server failed to start. Co-Authored-By: Claude Opus 5.5 --- lib/pact/consumer/http_interaction_builder.rb | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/pact/consumer/http_interaction_builder.rb b/lib/pact/consumer/http_interaction_builder.rb index 37782046..cc3eab73 100644 --- a/lib/pact/consumer/http_interaction_builder.rb +++ b/lib/pact/consumer/http_interaction_builder.rb @@ -126,17 +126,21 @@ def execute(&block) yield(mock_server) ensure - if mock_server.matched? - mock_server.write_pacts!(pact_config.pact_dir) - else - msg = mismatches_error_msg(mock_server) - raise InteractionMismatchesError.new(msg) + begin + if mock_server&.matched? + mock_server.write_pacts!(pact_config.pact_dir) + elsif mock_server + msg = mismatches_error_msg(mock_server) + raise InteractionMismatchesError.new(msg) + end + ensure + # Always release the mock server port, even when there are mismatches + @used = true + mock_server&.cleanup + # Reset the pact handle to allow for a new interaction to be built + # without previous interactions being included + @pact_config.reset_pact end - @used = true - mock_server&.cleanup - # Reset the pact handle to allow for a new interaction to be built - # without previous interactions being included - @pact_config.reset_pact end private From 8c56611b5412d989ba5cf7f48547db4b8062ec54 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 9 Nov 2026 17:31:23 +0000 Subject: [PATCH 3/5] test(consumer): cover OR matchers in body, header and query against the mock server Proves each alternative matches, a value matching none fails, nested rules in a null-or-object sample still apply, and the written pact contains `"combine": "OR"` rule lists. Uses a separate consumer name and a temp pact dir so the provider verification does not replay it. Co-Authored-By: Claude Opus 5.5 --- .../pact-ruby-v2-test-app/http_client_spec.rb | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/spec/pact/providers/pact-ruby-v2-test-app/http_client_spec.rb b/spec/pact/providers/pact-ruby-v2-test-app/http_client_spec.rb index d21f44cc..d8d336c3 100644 --- a/spec/pact/providers/pact-ruby-v2-test-app/http_client_spec.rb +++ b/spec/pact/providers/pact-ruby-v2-test-app/http_client_spec.rb @@ -79,3 +79,104 @@ end end end + +# OR / AND combined matchers (pact_ffi integration JSON `pact:matcher:combine`). +# Uses its own consumer name and pact dir so the interactions are not replayed +# against the test app by the provider verification in spec/pact/consumers. +RSpec.describe 'PactProviders::Test::HttpClient combined matchers', :pact do + or_pact_dir = Dir.mktmpdir('pact-ruby-or-matcher') + + has_http_pact_between 'pact-ruby-or-matcher-consumer', 'pact-ruby-or-matcher-provider', opts: { + mock_port: 3010, + pact_dir: or_pact_dir + } + + let(:host) { 'localhost:3010' } + let(:pact_file) { File.join(or_pact_dir, 'pact-ruby-or-matcher-consumer-pact-ruby-or-matcher-provider.json') } + let(:http_client) do + Faraday.new do |conn| + conn.response :json + conn.request :json + end + end + + let(:interaction) do + new_interaction + .upon_receiving('creating a pet with nullable fields') + .with_request( + method: :post, + path: '/pets', + query: { limit: match_or(match_regex(/^\d+$/, '10'), match_regex(/^all$/, 'all'), sample: '10') }, + headers: { + 'X-Request-Id' => match_or(match_regex(/^\d+$/, '123'), match_uuid, sample: '123') + }, + body: { + name: match_any_string_or_nil('Rex'), + owner: match_or( + match_type_of({}), match_null, + sample: { name: 'Bob', age: match_any_integer(30) } + ) + } + ) + .will_respond_with(status: 201) + end + + def post_pet(limit:, request_id:, body:) + http_client.post("http://#{host}/pets?limit=#{limit}", body.to_json, + { 'X-Request-Id' => request_id, 'Content-Type' => 'application/json' }) + end + + it 'matches the sample values' do + interaction.execute do + expect(post_pet(limit: '10', request_id: '123', body: { name: 'Rex', owner: { name: 'Bob', age: 30 } }).status) + .to eq(201) + end + end + + it 'matches the other alternatives (null, uuid, literal)' do + interaction.execute do + expect(post_pet(limit: 'all', request_id: 'e1d01e04-3a2b-4eed-a4fb-54f5cd257338', + body: { name: nil, owner: nil }).status).to eq(201) + end + end + + it 'still applies nested rules inside a non-null object sample' do + expect do + interaction.execute do + post_pet(limit: '5', request_id: '9', body: { name: 'Fido', owner: { name: 'Al', age: 'old' } }) + end + end.to raise_error(Pact::Consumer::HttpInteractionBuilder::InteractionMismatchesError, /\$\.owner\.age/) + end + + it 'fails when a value matches none of the alternatives' do + expect do + interaction.execute do + post_pet(limit: 'some', request_id: 'not-an-id', body: { name: 'Rex', owner: 'nobody' }) + end + end.to raise_error(Pact::Consumer::HttpInteractionBuilder::InteractionMismatchesError) { |error| + expect(error.message).to include( + "Expected 'nobody' (String) to be a null value", + "Expected 'not-an-id' to match", + "Expected 'some' to match '(?-mix:^all$)'" + ) + } + end + + it 'writes combine OR rules to the pact file' do + interaction.execute do + post_pet(limit: '10', request_id: '123', body: { name: 'Rex', owner: { name: 'Bob', age: 30 } }) + end + + request = JSON.parse(File.read(pact_file))['interactions'].first['request'] + rules = request['matchingRules'] + expect(rules['body']['$.name']).to include('combine' => 'OR', + 'matchers' => [a_hash_including('match' => 'regex'), + { 'match' => 'null' }]) + expect(rules['body']['$.owner']).to eq('combine' => 'OR', + 'matchers' => [{ 'match' => 'type' }, { 'match' => 'null' }]) + expect(rules['body']['$.owner.age']['matchers']).to eq([{ 'match' => 'integer' }]) + expect(rules['header']['X-Request-Id']).to include('combine' => 'OR') + expect(rules['query']['limit']).to include('combine' => 'OR') + expect(request['body']['content']).to eq('name' => 'Rex', 'owner' => { 'name' => 'Bob', 'age' => 30 }) + end +end From 121e5dd2d699ec8912804e6a78637b555c59d6f1 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 9 Nov 2026 17:31:48 +0000 Subject: [PATCH 4/5] docs: document match_or, match_and, match_null and the *_or_nil helpers Co-Authored-By: Claude Opus 5.5 --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index 1b726fbe..c3bb98b7 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,53 @@ For details of the implementation, see [matchers.rb](../lib/pact/matchers.rb) See the different uses of the matchers in [matchers_spec.rb](../spec/pact/matchers_spec.rb) +#### Combining matchers (OR / AND) + +> Requires a pact_ffi version with `pact:matcher:combine` support ([pact-foundation/pact-reference#601](https://github.com/pact-foundation/pact-reference/pull/601)): pact_ffi TODO(version). + +- `match_or(*matchers, sample:)` - the value must match at least one of the matchers +- `match_and(*matchers, sample:)` - the value must match all of the matchers +- `match_null` - match a JSON `null` (mostly useful inside `match_or`) +- `*_or_nil` helpers - shorthand for `match_or(, match_null, sample: sample)`: + `match_any_string_or_nil`, `match_any_integer_or_nil`, `match_any_decimal_or_nil`, `match_any_number_or_nil`, + `match_any_boolean_or_nil`, `match_any_uuid_or_nil`, `match_regex_or_nil`, `match_datetime_or_nil`, + `match_iso8601_or_nil`, `match_date_or_nil`, `match_time_or_nil` + +Combined matchers can be used in request/response bodies, headers and query parameters: + +```ruby +.with_request( + method: :post, + path: '/pets', + query: { limit: match_or(match_regex(/^\d+$/, '10'), match_regex(/^all$/, 'all'), sample: '10') }, + headers: { 'X-Request-Id' => match_or(match_regex(/^\d+$/, '123'), match_uuid, sample: '123') }, + body: { + name: match_any_string_or_nil('Rex'), + # null, or an object whose `age` is an integer + owner: match_or( + match_type_of({}), match_null, + sample: { name: 'Bob', age: match_any_integer(30) } + ) + } +) +``` + +Each matcher is sent to pact_ffi without its own example; `sample:` is the one example value used for the path. +Matchers nested inside an object `sample` (like `age` above) still apply to its children whenever the value is not +`null`. Put every alternative in the one `match_or`/`match_and` call; combined matchers cannot be nested inside each +other, and are not supported in plugin (`matching(...)`) contents. + +The Pact file gets a rule list combined with `OR`/`AND`, which Pact specification V3 and V4 support: + +```json +"$.owner": { "combine": "OR", "matchers": [{ "match": "type" }, { "match": "null" }] } +``` + +**Caveat:** only the `sample` is exercised in the consumer test. In a response, the mock server always returns the +sample, so your consumer code is never run against the other alternatives (e.g. `null`); the provider verification +checks that the real response matches one of them. Add a separate interaction (e.g. with a `null` sample) if your +consumer must be tested against each case. + ### Generators Generators are helper methods that allow you to specify dynamic values in your contract tests. These values are generated at runtime, making your contracts more flexible and robust. Below are the available generator methods: From b969bc3e427a7c41dd0bf7e807347b254ff08fb9 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 9 Nov 2026 19:01:09 +0000 Subject: [PATCH 5/5] test: consume pact_ffi 0.5.13-or.1 from YOU54F/pact-reference fork (revert before merge) CI clones the YOU54F/pact-ruby-ffi PR branch, whose download script fetches the rc, and points pact-ffi at it with DEBUG_TARGET. The pact-ffi gem cannot come from git: its native libraries are not committed. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a5924d52..2eeeae78 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,19 @@ jobs: with: ruby-version: ${{ matrix.ruby_version }} bundler-cache: true + # TEMP: load libpact_ffi 0.5.13-or.1 (YOU54F/pact-reference fork prerelease), + # fetched by the YOU54F/pact-ruby-ffi PR branch's download script, through + # pact-ffi's DEBUG_TARGET override (revert before merge) + - name: Use pact_ffi 0.5.13-or.1 from YOU54F/pact-ruby-ffi + shell: bash + run: | + git clone --depth 1 --branch feat/or-matcher https://github.com/YOU54F/pact-ruby-ffi.git ../pact-ruby-ffi + cd ../pact-ruby-ffi + ruby script/download_libs.rb + echo "DEBUG_TARGET=$(ruby -r ./lib/pact/detect_os -e 'print File.expand_path(DetectOS.get_bin_path)')" >> "$GITHUB_ENV" + - name: Check loaded pact_ffi version + shell: bash + run: bundle exec ruby -e 'require "pact/ffi"; v = PactFfi.version; puts "DEBUG_TARGET=#{ENV["DEBUG_TARGET"]} pact_ffi=#{v}"; abort "expected pact_ffi 0.5.13-or.1" unless v == "0.5.13-or.1"' - uses: pact-foundation/pact-cli@main - run: pact plugin install --yes https://github.com/mefellows/pact-matt-plugin/releases/tag/v0.1.1 - name: Test Pact-Ruby Specs @@ -52,6 +65,19 @@ jobs: with: ruby-version: ${{ matrix.ruby_version }} bundler-cache: true + # TEMP: load libpact_ffi 0.5.13-or.1 (YOU54F/pact-reference fork prerelease), + # fetched by the YOU54F/pact-ruby-ffi PR branch's download script, through + # pact-ffi's DEBUG_TARGET override (revert before merge) + - name: Use pact_ffi 0.5.13-or.1 from YOU54F/pact-ruby-ffi + shell: bash + run: | + git clone --depth 1 --branch feat/or-matcher https://github.com/YOU54F/pact-ruby-ffi.git ../pact-ruby-ffi + cd ../pact-ruby-ffi + ruby script/download_libs.rb + echo "DEBUG_TARGET=$(ruby -r ./lib/pact/detect_os -e 'print File.expand_path(DetectOS.get_bin_path)')" >> "$GITHUB_ENV" + - name: Check loaded pact_ffi version + shell: bash + run: bundle exec ruby -e 'require "pact/ffi"; v = PactFfi.version; puts "DEBUG_TARGET=#{ENV["DEBUG_TARGET"]} pact_ffi=#{v}"; abort "expected pact_ffi 0.5.13-or.1" unless v == "0.5.13-or.1"' - uses: pact-foundation/pact-cli@main - run: pact plugin install --yes https://github.com/mefellows/pact-matt-plugin/releases/tag/v0.1.1 - run: "bundle exec appraisal install"