Skip to content

Commit

Permalink
feat: update output during verification so the pact info shows before…
Browse files Browse the repository at this point in the history
… the describe blocks of the pact that is being verified
  • Loading branch information
bethesque committed Sep 16, 2020
1 parent f018ac4 commit 15ec231
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/pact/provider/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,34 @@ module ClassMethods
def honour_pactfile pact_source, pact_json, options
pact_uri = pact_source.uri
Pact.configuration.output_stream.puts "INFO: Reading pact at #{pact_uri}"
if pact_uri.metadata[:notices]
pact_uri.metadata[:notices].before_verification_notices_text.each do | text |
Pact.configuration.output_stream.puts("DEBUG: #{text}")
end
end

Pact.configuration.output_stream.puts "DEBUG: Filtering interactions by: #{options[:criteria]}" if options[:criteria] && options[:criteria].any?
consumer_contract = Pact::ConsumerContract.from_json(pact_json)
suffix = pact_uri.metadata[:pending] ? " [PENDING]": ""

::RSpec.describe "Verifying a pact between #{consumer_contract.consumer.name} and #{consumer_contract.provider.name}#{suffix}", pactfile_uri: pact_uri do
honour_consumer_contract consumer_contract, options.merge(pact_json: pact_json, pact_uri: pact_uri, pact_source: pact_source, consumer_contract: consumer_contract)
honour_consumer_contract consumer_contract, options.merge(
pact_json: pact_json,
pact_uri: pact_uri,
pact_source: pact_source,
consumer_contract: consumer_contract,
criteria: options[:criteria]
)
end
end

def honour_consumer_contract consumer_contract, options = {}
describe_consumer_contract consumer_contract, options.merge(consumer: consumer_contract.consumer.name)
describe_consumer_contract consumer_contract, options.merge(consumer: consumer_contract.consumer.name, pact_context: InteractionContext.new)
end

private

def describe_consumer_contract consumer_contract, options
consumer_interactions(consumer_contract, options).each do |interaction|
consumer_interactions(consumer_contract, options).tap{ |interactions|
if interactions.empty?
# If there are no interactions, the documentation formatter never fires to print this out,
# so print it out here.
Pact.configuration.output_stream.puts "DEBUG: All interactions for #{options[:pact_uri]} have been filtered out by criteria: #{options[:criteria]}" if options[:criteria] && options[:criteria].any?
end
}.each do |interaction|
describe_interaction_with_provider_state interaction, options
end
end
Expand All @@ -54,7 +60,7 @@ def consumer_interactions(consumer_contract, options)
if options[:criteria].nil?
consumer_contract.interactions
else
consumer_contract.find_interactions options[:criteria]
consumer_contract.find_interactions(options[:criteria])
end
end

Expand Down Expand Up @@ -84,14 +90,19 @@ def describe_interaction interaction, options
pact_uri: options[:pact_uri],
pact_source: options[:pact_source],
pact_ignore_failures: options[:pact_uri].metadata[:pending] || options[:ignore_failures],
pact_consumer_contract: options[:consumer_contract]
pact_consumer_contract: options[:consumer_contract],
pact_criteria: options[:criteria]
}

describe description_for(interaction), metadata do

interaction_context = InteractionContext.new
pact_context = options[:pact_context]

before do | example |
pact_context.run_once :before do
::RSpec.configuration.reporter.message "THIS IS A PACT"
end
interaction_context.run_once :before do
Pact.configuration.logger.info "Running example '#{Pact::RSpec.full_description(example)}'"
set_up_provider_states interaction.provider_states, options[:consumer]
Expand Down
19 changes: 19 additions & 0 deletions lib/pact/provider/rspec/formatter_rspec_3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ def dump_summary(summary)

C = ::Term::ANSIColor

def example_group_started(notification)
if @group_level == 0
Pact.configuration.output_stream.puts
pact_uri = notification.group.metadata[:pactfile_uri]
::RSpec.configuration.failure_color = pact_uri.metadata[:pending] ? :yellow : :red

if pact_uri.metadata[:notices]
pact_uri.metadata[:notices].before_verification_notices_text.each do | text |
Pact.configuration.output_stream.puts("DEBUG: #{text}")
end
end

criteria = notification.group.metadata[:pact_criteria]
Pact.configuration.output_stream.puts "DEBUG: Filtering interactions by: #{criteria}" if criteria && criteria.any?
end
super
end


def dump_summary(summary)
output.puts "\n" + colorized_totals_line(summary)
return if summary.failure_count == 0
Expand Down

0 comments on commit 15ec231

Please sign in to comment.