Skip to content

Commit 6c703a1

Browse files
committed
feat: use custom json formatter when --format json is specified and send it straight to stdout or the configured file
1 parent c5cc792 commit 6c703a1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/pact/provider/pact_spec_runner.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,13 @@ def configure_output
133133

134134
output = options[:out] || Pact.configuration.output_stream
135135
if options[:format]
136-
::RSpec.configuration.add_formatter options[:format], output
137-
if !options[:out]
138-
# Don't want to mess up the JSON parsing with messages to stdout, so send it to stderr
139-
Pact.configuration.output_stream = Pact.configuration.error_stream
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
140143
end
141144
else
142145
# Sometimes the formatter set in the cli.rb get set with an output of StringIO.. don't know why

0 commit comments

Comments
 (0)