Skip to content

Commit

Permalink
feat: allow output streams and consumer contract writer to be passed …
Browse files Browse the repository at this point in the history
…in to Pact::ConsumerContractWriter

This is to support pact-message.
  • Loading branch information
bethesque committed Feb 14, 2018
1 parent 8d90910 commit 1856f21
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/pact/consumer_contract/consumer_contract_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def initialize consumer_contract_details, logger
@pactfile_write_mode = (consumer_contract_details[:pactfile_write_mode] || :overwrite).to_sym
@interactions = consumer_contract_details.fetch(:interactions)
@pact_specification_version = (consumer_contract_details[:pact_specification_version] || DEFAULT_PACT_SPECIFICATION_VERSION).to_s
@consumer_contract_decorator_class = consumer_contract_details[:consumer_contract_decorator_class] || Pact::ConsumerContractDecorator
@error_stream = consumer_contract_details[:error_stream] || Pact.configuration.error_stream
@output_stream = consumer_contract_details[:output_stream] || Pact.configuration.output_stream
end

def consumer_contract
Expand All @@ -45,7 +48,8 @@ def can_write?

private

attr_reader :consumer_contract_details, :pactfile_write_mode, :interactions, :logger, :pact_specification_version
attr_reader :consumer_contract_details, :pactfile_write_mode, :interactions, :logger, :pact_specification_version, :consumer_contract_decorator_class
attr_reader :error_stream, :output_stream

def update_pactfile_if_needed
return if pactfile_write_mode == :none
Expand All @@ -68,7 +72,7 @@ def pact_json
end

def decorated_pact
@decorated_pact ||= Pact::ConsumerContractDecorator.new(consumer_contract, pact_specification_version: pact_specification_version)
@decorated_pact ||= consumer_contract_decorator_class.new(consumer_contract, pact_specification_version: pact_specification_version)
end

def interactions_for_new_consumer_contract
Expand Down Expand Up @@ -111,12 +115,12 @@ def existing_consumer_contract
end

def warn_and_stderr msg
Pact.configuration.error_stream.puts msg
error_stream.puts msg
logger.warn msg
end

def info_and_puts msg
$stdout.puts msg
output_stream.puts msg
logger.info msg
end

Expand Down

0 comments on commit 1856f21

Please sign in to comment.