forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…reduce noise.
- Loading branch information
1 parent
589c6e8
commit 29d104e
Showing
4 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec::Support.require_rspec_core 'formatters/base_text_formatter' | ||
RSpec::Support.require_rspec_core 'formatters/console_codes' | ||
|
||
module RuboCop | ||
module RSpec | ||
# RSpec formatter for use with running `rake spec` in parallel. This formatter | ||
# removes much of the noise from RSpec so that only the important information | ||
# will be surfaced by test-queue. | ||
# It also adds metadata to the output in order to more easily find the text | ||
# needed for outputting after the parallel run completes. | ||
class ParallelFormatter < ::RSpec::Core::Formatters::BaseTextFormatter | ||
::RSpec::Core::Formatters.register self, :dump_pending, :dump_failures, :dump_summary | ||
|
||
# Don't show pending tests | ||
def dump_pending(*); end | ||
|
||
# The BEGIN/END comments are used by `spec_runner.rake` to determine what | ||
# output goes where in the final parallelized output, and should not be | ||
# removed! | ||
def dump_failures(notification) | ||
return if notification.failure_notifications.empty? | ||
|
||
output.puts '# FAILURES BEGIN' | ||
notification.failure_notifications.each do |failure| | ||
output.puts failure.fully_formatted('*', colorizer) | ||
end | ||
output.puts | ||
output.puts '# FAILURES END' | ||
end | ||
|
||
def dump_summary(summary) | ||
output_summary(summary) | ||
output_rerun_commands(summary) | ||
end | ||
|
||
private | ||
|
||
def colorizer | ||
@colorizer ||= ::RSpec::Core::Formatters::ConsoleCodes | ||
end | ||
|
||
# The BEGIN/END comments are used by `spec_runner.rake` to determine what | ||
# output goes where in the final parallelized output, and should not be | ||
# removed! | ||
def output_summary(summary) | ||
output.puts '# SUMMARY BEGIN' | ||
output.puts colorize_summary(summary) | ||
output.puts '# SUMMARY END' | ||
end | ||
|
||
def colorize_summary(summary) | ||
totals = totals(summary) | ||
|
||
if summary.failure_count.positive? || summary.errors_outside_of_examples_count.positive? | ||
colorizer.wrap(totals, ::RSpec.configuration.failure_color) | ||
else | ||
colorizer.wrap(totals, ::RSpec.configuration.success_color) | ||
end | ||
end | ||
|
||
# The BEGIN/END comments are used by `spec_runner.rake` to determine what | ||
# output goes where in the final parallelized output, and should not be | ||
# removed! | ||
def output_rerun_commands(summary) | ||
output.puts '# RERUN BEGIN' | ||
output.puts summary.colorized_rerun_commands.lines[3..-1].join | ||
output.puts '# RERUN END' | ||
end | ||
|
||
def totals(summary) | ||
output = pluralize(summary.example_count, 'example') | ||
output += ", #{summary.pending_count} pending" if summary.pending_count.positive? | ||
output += ", #{pluralize(summary.failure_count, 'failure')}" | ||
|
||
if summary.errors_outside_of_examples_count.positive? | ||
error_count = pluralize(summary.errors_outside_of_examples_count, 'error') | ||
output += ", #{error_count} occurred outside of examples" | ||
end | ||
|
||
output | ||
end | ||
|
||
def pluralize(*args) | ||
::RSpec::Core::Formatters::Helpers.pluralize(*args) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters