Skip to content

Commit

Permalink
feat: use custom json formatter when --format json is specified and s…
Browse files Browse the repository at this point in the history
…end it straight to stdout or the configured file
  • Loading branch information
bethesque committed Jan 20, 2020
1 parent c5cc792 commit 6c703a1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/pact/provider/pact_spec_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,13 @@ def configure_output

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

0 comments on commit 6c703a1

Please sign in to comment.