Skip to content

Commit 09e9d89

Browse files
committed
feat: add actual pact message contents to results published to Pact Broker
1 parent 838057a commit 09e9d89

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/pact/provider/rspec.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,21 @@ def describe_message expected_response, interaction_context
110110
include Pact::RSpec::Matchers
111111
extend Pact::Matchers::Messages
112112

113-
let(:expected_content) { expected_response.body[:contents].as_json }
113+
let(:expected_contents) { expected_response.body[:contents].as_json }
114114
let(:response) { interaction_context.last_response }
115115
let(:differ) { Pact.configuration.body_differ_for_content_type diff_content_type }
116116
let(:diff_formatter) { Pact.configuration.diff_formatter_for_content_type diff_content_type }
117117
let(:diff_options) { { with: differ, diff_formatter: diff_formatter } }
118118
let(:diff_content_type) { 'application/json' }
119119
let(:response_body) { parse_body_from_response(response) }
120-
let(:actual_content) { response_body['contents'] }
120+
let(:actual_contents) { response_body['contents'] }
121121

122122
it "has matching content" do | example |
123123
if response.status != 200
124124
raise "An error was raised while verifying the message. The response body is: #{response.body}"
125125
end
126-
expect(actual_content).to match_term expected_content, diff_options, example
126+
set_metadata(example, :pact_actual_contents, actual_contents)
127+
expect(actual_contents).to match_term expected_contents, diff_options, example
127128
end
128129
end
129130

lib/pact/provider/rspec/pact_broker_formatter.rb

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def format_example(example)
5959
hash[:actualBody] = example.metadata[:pact_actual_body]
6060
end
6161

62+
if example.metadata[:pact_actual_contents]
63+
hash[:actualContents] = example.metadata[:pact_actual_contents]
64+
end
65+
6266
if example.metadata[:pact_diff]
6367
hash[:differences] = Pact::Matchers::ExtractDiffMessages.call(example.metadata[:pact_diff])
6468
.to_a

0 commit comments

Comments
 (0)