From da2af9a331fb3563e5816853323b73c88b83d87f Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 9 Nov 2026 17:33:45 +0000 Subject: [PATCH 1/2] test: cover with_body with a pact:matcher:combine OR integration JSON matcher Requires a pact_ffi with combine support (pact-foundation/pact-reference#601). No library change is needed: with_body passes the integration JSON through. Co-Authored-By: Claude Opus 5.5 --- spec/pactffi_or_matcher_spec.rb | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 spec/pactffi_or_matcher_spec.rb diff --git a/spec/pactffi_or_matcher_spec.rb b/spec/pactffi_or_matcher_spec.rb new file mode 100644 index 0000000..713c3ec --- /dev/null +++ b/spec/pactffi_or_matcher_spec.rb @@ -0,0 +1,67 @@ +require 'httparty' +require 'json' +require 'tmpdir' +require 'pact/ffi' +require 'pact/ffi/logger' +require 'pact/ffi/mock_server' +require 'pact/ffi/http_consumer' + +PactFfi::Logger.log_to_buffer(PactFfi::Logger::LogLevel['ERROR']) + +# Requires a pact_ffi with `pact:matcher:combine` support (pact-foundation/pact-reference#601) +RSpec.describe 'with_body with an OR (pact:matcher:combine) integration JSON matcher' do + let(:request_body) do + { + name: { + 'pact:matcher:type': [{ 'pact:matcher:type': 'type' }, { 'pact:matcher:type': 'null' }], + 'pact:matcher:combine': 'OR', + value: 'Fred' + } + }.to_json + end + + let(:pact) { PactFfi.new_pact('or-matcher-consumer', 'or-matcher-provider') } + let(:interaction) { PactFfi::HttpConsumer.new_interaction(pact, 'a request with a nullable name') } + let(:mock_server_port) { PactFfi::MockServer.create_for_transport(pact, '127.0.0.1', 0, 'http', nil) } + let(:pact_dir) { Dir.mktmpdir } + + before do + request_part = PactFfi::FfiInteractionPart['INTERACTION_PART_REQUEST'] + PactFfi::HttpConsumer.with_specification(pact, PactFfi::FfiSpecificationVersion['SPECIFICATION_VERSION_V3']) + PactFfi::HttpConsumer.upon_receiving(interaction, 'a request with a nullable name') + PactFfi::HttpConsumer.with_request(interaction, 'POST', '/people') + PactFfi::HttpConsumer.with_header(interaction, request_part, 'Content-Type', 0, 'application/json') + PactFfi::HttpConsumer.with_body(interaction, request_part, 'application/json', request_body) + PactFfi::HttpConsumer.response_status(interaction, 201) + end + + after do + PactFfi::MockServer.cleanup(mock_server_port) + FileUtils.remove_entry(pact_dir) + end + + def post(name) + HTTParty.post("http://127.0.0.1:#{mock_server_port}/people", + body: { name: name }.to_json, headers: { 'Content-Type' => 'application/json' }) + end + + ['Wilma', nil].each do |name| + it "matches #{name.inspect} and writes a combine OR rule" do + expect(post(name).code).to eq(201) + expect(PactFfi::MockServer.matched(mock_server_port)).to be true + expect(PactFfi::MockServer.write_pact_file(mock_server_port, pact_dir, false)).to eq(0) + + written = JSON.parse(File.read(File.join(pact_dir, 'or-matcher-consumer-or-matcher-provider.json'))) + request = written['interactions'].first['request'] + expect(request['body']).to eq('name' => 'Fred') + expect(request['matchingRules']['body']['$.name']) + .to eq('combine' => 'OR', 'matchers' => [{ 'match' => 'type' }, { 'match' => 'null' }]) + end + end + + it 'does not match a value matching neither alternative' do + post(42) + expect(PactFfi::MockServer.matched(mock_server_port)).to be false + expect(PactFfi::MockServer.mismatches(mock_server_port)).to include('$.name') + end +end From 874d24d8afd469f6eecb7b0b90682153d7229523 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 9 Nov 2026 19:01:10 +0000 Subject: [PATCH 2/2] test: consume pact_ffi 0.5.13-or.1 from YOU54F/pact-reference fork (revert before merge) Co-Authored-By: Claude Opus 5.5 --- script/download_libs.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/download_libs.rb b/script/download_libs.rb index 63ac2d8..f7c69b7 100644 --- a/script/download_libs.rb +++ b/script/download_libs.rb @@ -18,7 +18,9 @@ require_relative '../lib/pact/ffi/version' ROOT = File.expand_path('..', __dir__) -FFI_BASE_URL = 'https://github.com/pact-foundation/pact-reference/releases/download' +# TEMP: consume the pact_ffi 0.5.13-or.1 fork prerelease (revert before merge) +FFI_BASE_URL = 'https://github.com/YOU54F/pact-reference/releases/download' +FFI_VERSION_OVERRIDE = 'v0.5.13-or.1' STANDALONE_BASE_URL = 'https://github.com/pact-foundation/pact-standalone/releases/download' STANDALONE_VERSION = '2.5.2' @@ -37,6 +39,8 @@ def log(msg) = puts "🔵 #{msg}" def ffi_version + return FFI_VERSION_OVERRIDE if FFI_VERSION_OVERRIDE + "v#{Pact::Version::VERSION.split('.')[0..2].join('.')}" end