From 09e9d89062d3d23ba4b864a248d1b11d34a794c1 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 25 Jul 2018 15:12:56 +1000 Subject: [PATCH] feat: add actual pact message contents to results published to Pact Broker --- lib/pact/provider/rspec.rb | 7 ++++--- lib/pact/provider/rspec/pact_broker_formatter.rb | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pact/provider/rspec.rb b/lib/pact/provider/rspec.rb index 923b3242..70616e43 100644 --- a/lib/pact/provider/rspec.rb +++ b/lib/pact/provider/rspec.rb @@ -110,20 +110,21 @@ def describe_message expected_response, interaction_context include Pact::RSpec::Matchers extend Pact::Matchers::Messages - let(:expected_content) { expected_response.body[:contents].as_json } + let(:expected_contents) { expected_response.body[:contents].as_json } let(:response) { interaction_context.last_response } let(:differ) { Pact.configuration.body_differ_for_content_type diff_content_type } let(:diff_formatter) { Pact.configuration.diff_formatter_for_content_type diff_content_type } let(:diff_options) { { with: differ, diff_formatter: diff_formatter } } let(:diff_content_type) { 'application/json' } let(:response_body) { parse_body_from_response(response) } - let(:actual_content) { response_body['contents'] } + let(:actual_contents) { response_body['contents'] } it "has matching content" do | example | if response.status != 200 raise "An error was raised while verifying the message. The response body is: #{response.body}" end - expect(actual_content).to match_term expected_content, diff_options, example + set_metadata(example, :pact_actual_contents, actual_contents) + expect(actual_contents).to match_term expected_contents, diff_options, example end end diff --git a/lib/pact/provider/rspec/pact_broker_formatter.rb b/lib/pact/provider/rspec/pact_broker_formatter.rb index 0383062d..c2659ddd 100644 --- a/lib/pact/provider/rspec/pact_broker_formatter.rb +++ b/lib/pact/provider/rspec/pact_broker_formatter.rb @@ -59,6 +59,10 @@ def format_example(example) hash[:actualBody] = example.metadata[:pact_actual_body] end + if example.metadata[:pact_actual_contents] + hash[:actualContents] = example.metadata[:pact_actual_contents] + end + if example.metadata[:pact_diff] hash[:differences] = Pact::Matchers::ExtractDiffMessages.call(example.metadata[:pact_diff]) .to_a