@@ -62,21 +62,7 @@ def configure_rspec
6262 config . output_stream = Pact . configuration . output_stream
6363 end
6464
65- Pact ::RSpec . with_rspec_3 do
66- ::RSpec . configuration . add_formatter Pact ::Provider ::RSpec ::PactBrokerFormatter , StringIO . new
67- end
68-
69- if options [ :format ]
70- ::RSpec . configuration . add_formatter options [ :format ]
71- # Don't want to mess up the JSON parsing with messages to stdout, so send it to stderr
72- Pact . configuration . output_stream = Pact . configuration . error_stream
73- else
74- # Sometimes the formatter set in the cli.rb get set with an output of StringIO.. don't know why
75- formatter_class = Pact ::RSpec . formatter_class
76- pact_formatter = ::RSpec . configuration . formatters . find { |f | f . class == formatter_class && f . output == ::RSpec . configuration . output_stream }
77- ::RSpec . configuration . add_formatter formatter_class unless pact_formatter
78- end
79- ::RSpec . configuration . full_backtrace = @options [ :full_backtrace ]
65+ configure_output
8066
8167 config . before ( :suite ) do
8268 # Preload app before suite so the classes loaded in memory are consistent for
@@ -138,6 +124,28 @@ def initialize_specs
138124 end
139125 end
140126
127+ def configure_output
128+ Pact ::RSpec . with_rspec_3 do
129+ ::RSpec . configuration . add_formatter Pact ::Provider ::RSpec ::PactBrokerFormatter , StringIO . new
130+ end
131+
132+ output = options [ :out ] || Pact . configuration . output_stream
133+ if options [ :format ]
134+ ::RSpec . configuration . add_formatter options [ :format ] , output
135+ if !options [ :out ]
136+ # Don't want to mess up the JSON parsing with messages to stdout, so send it to stderr
137+ Pact . configuration . output_stream = Pact . configuration . error_stream
138+ end
139+ else
140+ # Sometimes the formatter set in the cli.rb get set with an output of StringIO.. don't know why
141+ formatter_class = Pact ::RSpec . formatter_class
142+ pact_formatter = ::RSpec . configuration . formatters . find { |f | f . class == formatter_class && f . output == ::RSpec . configuration . output_stream }
143+ ::RSpec . configuration . add_formatter ( formatter_class , output ) unless pact_formatter
144+ end
145+
146+ ::RSpec . configuration . full_backtrace = @options [ :full_backtrace ]
147+ end
148+
141149 def ordered_pact_json ( pact_json )
142150 return pact_json if Pact . configuration . interactions_replay_order == :recorded
143151
0 commit comments