class Pact::Provider::RSpec::Formatter
Public Instance Methods
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 45 def dump_summary(summary) output.puts "\n" + colorized_totals_line(summary) return if summary.failure_count == 0 print_rerun_commands summary print_failure_message print_missing_provider_states end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 25 def example_group_started(notification) # This is the metadata on the top level "Verifying a pact between X and Y" describe block 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
Calls superclass method
Private Instance Methods
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 83 def color_for_summary summary summary.failure_count > 0 ? ::RSpec.configuration.failure_color : ::RSpec.configuration.success_color end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 79 def colorized_totals_line(summary) colorizer.wrap(totals_line(summary), color_for_summary(summary)) end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 180 def colorizer @colorizer ||= ::RSpec::Core::Formatters::ConsoleCodes end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 184 def executing_with_ruby? ENV['PACT_EXECUTING_LANGUAGE'] == 'ruby' end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 117 def failed_interaction_examples(summary) one_failed_example_per_interaction(summary).select do | example | !example.metadata[:pactfile_uri].metadata[:pending] end end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 59 def failed_interactions_count(summary) failed_interaction_examples(summary).size end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 176 def failure_message "\n" + Pact::Provider::Help::PromptText.() + "\n" end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 67 def failure_title summary ::RSpec::Core::Formatters::Helpers.pluralize(failed_interactions_count(summary), "failure") end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 141 def interaction_rerun_command_for example example_description = example.metadata[:pact_interaction_example_description] _id = example.metadata[:pact_interaction]._id index = example.metadata[:pact_interaction].index provider_state = example.metadata[:pact_interaction].provider_state description = example.metadata[:pact_interaction].description pactfile_uri = example.metadata[:pactfile_uri] if _id && ENV['PACT_INTERACTION_RERUN_COMMAND_FOR_BROKER'] cmd = String.new(ENV['PACT_INTERACTION_RERUN_COMMAND_FOR_BROKER']) cmd.gsub!("<PACT_URI>", example.metadata[:pactfile_uri].to_s) cmd.gsub!("<PACT_BROKER_INTERACTION_ID>", "#{_id}") colorizer.wrap("#{cmd} ", ::RSpec.configuration.failure_color) + colorizer.wrap("# #{example_description}", ::RSpec.configuration.detail_color) elsif ENV['PACT_INTERACTION_RERUN_COMMAND'] cmd = String.new(ENV['PACT_INTERACTION_RERUN_COMMAND']) cmd.gsub!("<PACT_URI>", pactfile_uri.to_s) cmd.gsub!("<PACT_DESCRIPTION>", description) cmd.gsub!("<PACT_PROVIDER_STATE>", "#{provider_state}") cmd.gsub!("<PACT_INTERACTION_INDEX>", "#{index}") colorizer.wrap("#{cmd} ", ::RSpec.configuration.failure_color) + colorizer.wrap("# #{example_description}", ::RSpec.configuration.detail_color) else message = if _id "* #{example_description} (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID=\"#{_id}\")" else "* #{example_description} (to re-run just this interaction, set environment variables PACT_DESCRIPTION=\"#{description}\" PACT_PROVIDER_STATE=\"#{provider_state}\")" end colorizer.wrap(message, ::RSpec.configuration.failure_color) end end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 127 def interaction_rerun_commands examples examples.collect do |example| interaction_rerun_command_for example end.compact.uniq end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 133 def interaction_unique_key(example) # pending is just to make the counting easier, it isn't required for the unique key { pactfile_uri: example.metadata[:pactfile_uri], index: example.metadata[:pact_interaction].index, } end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 55 def interactions_count(summary) summary.examples.collect{ |e| interaction_unique_key(e) }.uniq.size end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 123 def one_failed_example_per_interaction(summary) summary.failed_examples.group_by{| e| interaction_unique_key(e)}.values.collect(&:first) end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 111 def pending_interaction_examples(summary) one_failed_example_per_interaction(summary).select do | example | example.metadata[:pactfile_uri].metadata[:pending] end end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 63 def pending_interactions_count(summary) pending_interaction_examples(summary).size end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 172 def print_failure_message output.puts(failure_message) if executing_with_ruby? end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 105 def print_missing_provider_states if executing_with_ruby? PrintMissingProviderStates.call Pact.provider_world.provider_states.missing_provider_states, output end end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 87 def print_rerun_commands summary if pending_interactions_count(summary) > 0 set_rspec_failure_color(:yellow) output.puts("\nPending interactions: (Failures listed here are expected and do not affect your suite's status)\n\n") interaction_rerun_commands(pending_interaction_examples(summary)).each do | message | output.puts(message) end set_rspec_failure_color(:red) end if failed_interactions_count(summary) > 0 output.puts("\nFailed interactions:\n\n") interaction_rerun_commands(failed_interaction_examples(summary)).each do | message | output.puts(message) end end end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 188 def set_rspec_failure_color color ::RSpec.configuration.failure_color = color end
Source
# File lib/pact/provider/rspec/formatter_rspec_3.rb, line 71 def totals_line summary line = ::RSpec::Core::Formatters::Helpers.pluralize(interactions_count(summary), "interaction") line << ", " << failure_title(summary) pending_count = pending_interactions_count(summary) line << ", " << "#{pending_count} pending" if pending_count > 0 line end