Skip to content

Commit

Permalink
feat: add actual pact message contents to results published to Pact B…
Browse files Browse the repository at this point in the history
…roker
  • Loading branch information
bethesque committed Jul 25, 2018
1 parent 838057a commit 09e9d89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/pact/provider/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/pact/provider/rspec/pact_broker_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09e9d89

Please sign in to comment.