Skip to content

Commit

Permalink
feat: allow verbose flag to be set when publishing verifications
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 26, 2021
1 parent d6ce29f commit 9238e4c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/pact/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def self.exit_on_failure? # Thor 1.0 deprecation guard
method_option :pact_broker_password, aliases: "-w", desc: "Pact broker password"
method_option :pact_broker_token, aliases: "-k", desc: "Pact broker token"
method_option :backtrace, aliases: "-b", desc: "Show full backtrace", :default => false, :type => :boolean
method_option :verbose, aliases: "-v", desc: "Show verbose HTTP logging", :default => false, :type => :boolean
method_option :interactions_replay_order, aliases: "-o",
desc: "Interactions replay order: randomised or recorded (default)",
default: Pact.configuration.interactions_replay_order
Expand Down
1 change: 1 addition & 0 deletions lib/pact/cli/run_pact_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def run_with_configured_pacts_from_pact_helper
def pact_spec_options
{
full_backtrace: options[:backtrace],
verbose: options[:verbose] || ENV['VERBOSE'] == 'true',
criteria: SpecCriteria.call(options),
format: options[:format],
out: options[:out],
Expand Down
1 change: 1 addition & 0 deletions lib/pact/provider/pact_spec_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def configure_rspec
end

# For the Pact::Provider::RSpec::PactBrokerFormatter
Pact.provider_world.verbose = options[:verbose]
Pact.provider_world.pact_sources = pact_sources
jsons = pact_jsons
executing_with_ruby = executing_with_ruby?
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/provider/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def honour_pactfile pact_source, pact_json, options
pact_source: pact_source,
consumer_contract: consumer_contract,
criteria: options[:criteria]
)
)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pact/provider/rspec/pact_broker_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def stop(notification)
end

def close(_notification)
Pact::Provider::VerificationResults::PublishAll.call(Pact.provider_world.pact_sources, output_hash)
Pact::Provider::VerificationResults::PublishAll.call(Pact.provider_world.pact_sources, output_hash, { verbose: Pact.provider_world.verbose })
end

private
Expand Down
8 changes: 4 additions & 4 deletions lib/pact/provider/verification_results/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class Publish
PROVIDER_RELATION = 'pb:provider'.freeze
VERSION_TAG_RELATION = 'pb:version-tag'.freeze

def self.call pact_source, verification_result
new(pact_source, verification_result).call
def self.call pact_source, verification_result, options = {}
new(pact_source, verification_result, options).call
end

def initialize pact_source, verification_result
def initialize pact_source, verification_result, options = {}
@pact_source = pact_source
@verification_result = verification_result
http_client_options = pact_source.uri.options.reject{ |k, v| ![:username, :password, :token].include?(k) }
@http_client = Pact::Hal::HttpClient.new(http_client_options)
@http_client = Pact::Hal::HttpClient.new(http_client_options.merge(verbose: options[:verbose]))
@pact_entity = Pact::Hal::Entity.new(pact_source.uri, pact_source.pact_hash, http_client)
end

Expand Down
11 changes: 6 additions & 5 deletions lib/pact/provider/verification_results/publish_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ module Provider
module VerificationResults
class PublishAll

def self.call pact_sources, test_results_hash
new(pact_sources, test_results_hash).call
def self.call pact_sources, test_results_hash, options = {}
new(pact_sources, test_results_hash, options).call
end

def initialize pact_sources, test_results_hash
def initialize pact_sources, test_results_hash, options = {}
@pact_sources = pact_sources
@test_results_hash = test_results_hash
@options = options
end

def call
verification_results.collect do | (pact_source, verification_result) |
published = false
begin
published = Publish.call(pact_source, verification_result)
published = Publish.call(pact_source, verification_result, { verbose: options[:verbose] })
ensure
print_after_verification_notices(pact_source, verification_result, published)
end
Expand All @@ -42,7 +43,7 @@ def print_after_verification_notices(pact_source, verification_result, published
end
end

attr_reader :pact_sources, :test_results_hash
attr_reader :pact_sources, :test_results_hash, :options
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/provider/world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.clear_provider_world
module Provider
class World

attr_accessor :pact_sources, :failed_examples
attr_accessor :pact_sources, :failed_examples, :verbose

def provider_states
@provider_states_proxy ||= Pact::Provider::State::ProviderStateProxy.new
Expand Down

0 comments on commit 9238e4c

Please sign in to comment.