DEV: Restore the documentation format in system tests (#21471)

This commit is contained in:
Jarek Radosz
2023-05-12 11:13:52 +02:00
committed by GitHub
parent 177651fdbb
commit 19ac90536f
8 changed files with 75 additions and 15 deletions

View File

@ -0,0 +1,44 @@
# frozen_string_literal: true
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
module TurboTests
# An RSpec formatter that prepends the process id to all messages
class DocumentationFormatter < ::RSpec::Core::Formatters::BaseTextFormatter
RSpec::Core::Formatters.register(self, :example_failed, :example_passed, :example_pending)
def example_passed(notification)
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
"[#{notification.example.process_id}] #{notification.example.full_description}",
:success,
)
output.flush
end
def example_pending(notification)
message = notification.example.execution_result.pending_message
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
"[#{notification.example.process_id}] #{notification.example.full_description}" \
"(PENDING: #{message})",
:pending,
)
output.flush
end
def example_failed(notification)
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
"[#{notification.example.process_id}] #{notification.example.full_description}" \
"(FAILED - #{next_failure_index})",
:failure,
)
output.flush
end
private
def next_failure_index
@next_failure_index ||= 0
@next_failure_index += 1
end
end
end