Skip to content

Commit 1856f21

Browse files
committed
feat: allow output streams and consumer contract writer to be passed in to Pact::ConsumerContractWriter
This is to support pact-message.
1 parent 8d90910 commit 1856f21

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/pact/consumer_contract/consumer_contract_writer.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def initialize consumer_contract_details, logger
2525
@pactfile_write_mode = (consumer_contract_details[:pactfile_write_mode] || :overwrite).to_sym
2626
@interactions = consumer_contract_details.fetch(:interactions)
2727
@pact_specification_version = (consumer_contract_details[:pact_specification_version] || DEFAULT_PACT_SPECIFICATION_VERSION).to_s
28+
@consumer_contract_decorator_class = consumer_contract_details[:consumer_contract_decorator_class] || Pact::ConsumerContractDecorator
29+
@error_stream = consumer_contract_details[:error_stream] || Pact.configuration.error_stream
30+
@output_stream = consumer_contract_details[:output_stream] || Pact.configuration.output_stream
2831
end
2932

3033
def consumer_contract
@@ -45,7 +48,8 @@ def can_write?
4548

4649
private
4750

48-
attr_reader :consumer_contract_details, :pactfile_write_mode, :interactions, :logger, :pact_specification_version
51+
attr_reader :consumer_contract_details, :pactfile_write_mode, :interactions, :logger, :pact_specification_version, :consumer_contract_decorator_class
52+
attr_reader :error_stream, :output_stream
4953

5054
def update_pactfile_if_needed
5155
return if pactfile_write_mode == :none
@@ -68,7 +72,7 @@ def pact_json
6872
end
6973

7074
def decorated_pact
71-
@decorated_pact ||= Pact::ConsumerContractDecorator.new(consumer_contract, pact_specification_version: pact_specification_version)
75+
@decorated_pact ||= consumer_contract_decorator_class.new(consumer_contract, pact_specification_version: pact_specification_version)
7276
end
7377

7478
def interactions_for_new_consumer_contract
@@ -111,12 +115,12 @@ def existing_consumer_contract
111115
end
112116

113117
def warn_and_stderr msg
114-
Pact.configuration.error_stream.puts msg
118+
error_stream.puts msg
115119
logger.warn msg
116120
end
117121

118122
def info_and_puts msg
119-
$stdout.puts msg
123+
output_stream.puts msg
120124
logger.info msg
121125
end
122126

0 commit comments

Comments
 (0)