Skip to content

Commit e768a33

Browse files
committed
fix: send output messages to the correct stream when using the XML formatter
1 parent aa8ea5f commit e768a33

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/pact/provider/pact_spec_runner.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,12 @@ def configure_output
133133

134134
output = options[:out] || Pact.configuration.output_stream
135135
if options[:format]
136-
if options[:format] == 'json'
137-
# To avoid mixing JSON and logging, the output_stream will be set to the error_stream
138-
# in the pact-provider-verifier.
139-
# Send JSON to a file if configured, or straight to $stdout
140-
::RSpec.configuration.add_formatter Pact::Provider::RSpec::JsonFormatter, options[:out] || $stdout
141-
else
142-
::RSpec.configuration.add_formatter options[:format], output
143-
end
136+
formatter = options[:format] == 'json' ? Pact::Provider::RSpec::JsonFormatter : options[:format]
137+
# Send formatted output to $stdout for parsing, unless a file is specified
138+
output = options[:out] || $stdout
139+
::RSpec.configuration.add_formatter formatter, output
140+
# Don't want to mess up the JSON parsing with INFO and DEBUG messages to stdout, so send it to stderr
141+
Pact.configuration.output_stream = Pact.configuration.error_stream if !options[:out]
144142
else
145143
# Sometimes the formatter set in the cli.rb get set with an output of StringIO.. don't know why
146144
formatter_class = Pact::RSpec.formatter_class

0 commit comments

Comments
 (0)