Skip to content

Commit 15ec231

Browse files
committed
feat: update output during verification so the pact info shows before the describe blocks of the pact that is being verified
1 parent f018ac4 commit 15ec231

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

lib/pact/provider/rspec.rb

+23-12
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,34 @@ module ClassMethods
2424
def honour_pactfile pact_source, pact_json, options
2525
pact_uri = pact_source.uri
2626
Pact.configuration.output_stream.puts "INFO: Reading pact at #{pact_uri}"
27-
if pact_uri.metadata[:notices]
28-
pact_uri.metadata[:notices].before_verification_notices_text.each do | text |
29-
Pact.configuration.output_stream.puts("DEBUG: #{text}")
30-
end
31-
end
32-
33-
Pact.configuration.output_stream.puts "DEBUG: Filtering interactions by: #{options[:criteria]}" if options[:criteria] && options[:criteria].any?
3427
consumer_contract = Pact::ConsumerContract.from_json(pact_json)
3528
suffix = pact_uri.metadata[:pending] ? " [PENDING]": ""
29+
3630
::RSpec.describe "Verifying a pact between #{consumer_contract.consumer.name} and #{consumer_contract.provider.name}#{suffix}", pactfile_uri: pact_uri do
37-
honour_consumer_contract consumer_contract, options.merge(pact_json: pact_json, pact_uri: pact_uri, pact_source: pact_source, consumer_contract: consumer_contract)
31+
honour_consumer_contract consumer_contract, options.merge(
32+
pact_json: pact_json,
33+
pact_uri: pact_uri,
34+
pact_source: pact_source,
35+
consumer_contract: consumer_contract,
36+
criteria: options[:criteria]
37+
)
3838
end
3939
end
4040

4141
def honour_consumer_contract consumer_contract, options = {}
42-
describe_consumer_contract consumer_contract, options.merge(consumer: consumer_contract.consumer.name)
42+
describe_consumer_contract consumer_contract, options.merge(consumer: consumer_contract.consumer.name, pact_context: InteractionContext.new)
4343
end
4444

4545
private
4646

4747
def describe_consumer_contract consumer_contract, options
48-
consumer_interactions(consumer_contract, options).each do |interaction|
48+
consumer_interactions(consumer_contract, options).tap{ |interactions|
49+
if interactions.empty?
50+
# If there are no interactions, the documentation formatter never fires to print this out,
51+
# so print it out here.
52+
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?
53+
end
54+
}.each do |interaction|
4955
describe_interaction_with_provider_state interaction, options
5056
end
5157
end
@@ -54,7 +60,7 @@ def consumer_interactions(consumer_contract, options)
5460
if options[:criteria].nil?
5561
consumer_contract.interactions
5662
else
57-
consumer_contract.find_interactions options[:criteria]
63+
consumer_contract.find_interactions(options[:criteria])
5864
end
5965
end
6066

@@ -84,14 +90,19 @@ def describe_interaction interaction, options
8490
pact_uri: options[:pact_uri],
8591
pact_source: options[:pact_source],
8692
pact_ignore_failures: options[:pact_uri].metadata[:pending] || options[:ignore_failures],
87-
pact_consumer_contract: options[:consumer_contract]
93+
pact_consumer_contract: options[:consumer_contract],
94+
pact_criteria: options[:criteria]
8895
}
8996

9097
describe description_for(interaction), metadata do
9198

9299
interaction_context = InteractionContext.new
100+
pact_context = options[:pact_context]
93101

94102
before do | example |
103+
pact_context.run_once :before do
104+
::RSpec.configuration.reporter.message "THIS IS A PACT"
105+
end
95106
interaction_context.run_once :before do
96107
Pact.configuration.logger.info "Running example '#{Pact::RSpec.full_description(example)}'"
97108
set_up_provider_states interaction.provider_states, options[:consumer]

lib/pact/provider/rspec/formatter_rspec_3.rb

+19
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ def dump_summary(summary)
2424

2525
C = ::Term::ANSIColor
2626

27+
def example_group_started(notification)
28+
if @group_level == 0
29+
Pact.configuration.output_stream.puts
30+
pact_uri = notification.group.metadata[:pactfile_uri]
31+
::RSpec.configuration.failure_color = pact_uri.metadata[:pending] ? :yellow : :red
32+
33+
if pact_uri.metadata[:notices]
34+
pact_uri.metadata[:notices].before_verification_notices_text.each do | text |
35+
Pact.configuration.output_stream.puts("DEBUG: #{text}")
36+
end
37+
end
38+
39+
criteria = notification.group.metadata[:pact_criteria]
40+
Pact.configuration.output_stream.puts "DEBUG: Filtering interactions by: #{criteria}" if criteria && criteria.any?
41+
end
42+
super
43+
end
44+
45+
2746
def dump_summary(summary)
2847
output.puts "\n" + colorized_totals_line(summary)
2948
return if summary.failure_count == 0

0 commit comments

Comments
 (0)