discourse/lib/turbo_tests/progress_formatter.rb
Jarek Radosz eec10efc3d
DEV: Enable color CI output and tweak formatting (#21527)
* Color for turbo_rspec in CI (`progress` and `documentation` formats)
* Show "DONE" only when `documentation` formatter is used
* Fix formatting
* Collapse RSpec commands
* Add line wrapping to the `progress` formatter (to mitigate GH Actions issue)
2023-05-12 18:22:15 +02:00

53 lines
1.0 KiB
Ruby

# frozen_string_literal: true
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
module TurboTests
class ProgressFormatter < RSpec::Core::Formatters::BaseTextFormatter
LINE_LENGTH = 80
RSpec::Core::Formatters.register(
self,
:example_passed,
:example_pending,
:example_failed,
:start_dump,
)
def initialize(*args)
super
@examples = 0
end
def example_passed(_notification)
output.print RSpec::Core::Formatters::ConsoleCodes.wrap(".", :success)
wrap
end
def example_pending(_notification)
output.print RSpec::Core::Formatters::ConsoleCodes.wrap("*", :pending)
wrap
end
def example_failed(_notification)
output.print RSpec::Core::Formatters::ConsoleCodes.wrap("F", :failure)
wrap
end
def start_dump(_notification)
output.puts
end
private
def wrap
@examples += 1
if @examples == LINE_LENGTH
output.print "\n"
@examples = 0
end
end
end
end