From 376e47acf753d3fc6b242db651a89e03bcf88636 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sat, 8 Feb 2020 20:59:09 +1100 Subject: [PATCH] feat: update json formatter output --- lib/pact/provider/rspec/json_formatter.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/pact/provider/rspec/json_formatter.rb b/lib/pact/provider/rspec/json_formatter.rb index 5fa48b1c..a3d1eeae 100644 --- a/lib/pact/provider/rspec/json_formatter.rb +++ b/lib/pact/provider/rspec/json_formatter.rb @@ -22,12 +22,7 @@ def format_example(example) :line_number => example.metadata[:line_number], :run_time => example.execution_result.run_time, :mismatches => extract_differences(example), - :pact => { - consumer_name: example.metadata[:pact_consumer_contract].consumer.name, - provider_name: example.metadata[:pact_consumer_contract].provider.name, - url: example.metadata[:pact_uri].uri, - short_description: example.metadata[:pact_uri].metadata[:short_description] - } + :pact_url => example.metadata[:pact_uri].uri } end @@ -62,17 +57,21 @@ def calculate_status(example) # for the pacts will be mushed together in one collection, so it will be hard to know which notice # belongs to which pact. def pacts(summary) - pact_uris(summary).collect do | pact_uri | + unique_pact_metadatas(summary).collect do | example_metadata | + pact_uri = example_metadata[:pact_uri] notices = (pact_uri.metadata[:notices] && pact_uri.metadata[:notices].before_verification_notices) || [] { notices: notices, - url: pact_uri.uri + url: pact_uri.uri, + consumer_name: example_metadata[:pact_consumer_contract].consumer.name, + provider_name: example_metadata[:pact_consumer_contract].provider.name, + short_description: pact_uri.metadata[:short_description] } end end - def pact_uris(summary) - summary.examples.collect(&:metadata).collect{ |metadata| metadata[:pact_uri] }.uniq + def unique_pact_metadatas(summary) + summary.examples.collect(&:metadata).group_by{ | metadata | metadata[:pact_uri].uri }.values.collect(&:first) end def create_custom_summary(summary)