From e768a33d87e4d331f436cf9173bcf8eff389cde7 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 22 Jan 2020 13:13:27 +1100 Subject: [PATCH] fix: send output messages to the correct stream when using the XML formatter --- lib/pact/provider/pact_spec_runner.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/pact/provider/pact_spec_runner.rb b/lib/pact/provider/pact_spec_runner.rb index 37a692d4..faaa5f46 100644 --- a/lib/pact/provider/pact_spec_runner.rb +++ b/lib/pact/provider/pact_spec_runner.rb @@ -133,14 +133,12 @@ def configure_output output = options[:out] || Pact.configuration.output_stream if options[:format] - if options[:format] == 'json' - # To avoid mixing JSON and logging, the output_stream will be set to the error_stream - # in the pact-provider-verifier. - # Send JSON to a file if configured, or straight to $stdout - ::RSpec.configuration.add_formatter Pact::Provider::RSpec::JsonFormatter, options[:out] || $stdout - else - ::RSpec.configuration.add_formatter options[:format], output - end + formatter = options[:format] == 'json' ? Pact::Provider::RSpec::JsonFormatter : options[:format] + # Send formatted output to $stdout for parsing, unless a file is specified + output = options[:out] || $stdout + ::RSpec.configuration.add_formatter formatter, output + # Don't want to mess up the JSON parsing with INFO and DEBUG messages to stdout, so send it to stderr + Pact.configuration.output_stream = Pact.configuration.error_stream if !options[:out] else # Sometimes the formatter set in the cli.rb get set with an output of StringIO.. don't know why formatter_class = Pact::RSpec.formatter_class