Move failure command list to its own component

This commit is contained in:
Michael Miller 2021-05-16 17:13:06 -06:00
parent 2316377c6e
commit ed3ad662d2
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 26 additions and 19 deletions

View file

@ -0,0 +1,16 @@
require "./example_command"
module Spectator::Formatting::Components
struct FailureCommandList
def initialize(@failures : Enumerable(Example))
end
def to_s(io)
io.puts "Failed examples:"
io.puts
@failures.each do |failure|
io.puts ExampleCommand.new(failure).colorize(:red)
end
end
end
end

View file

@ -1,4 +1,3 @@
require "./example_command"
require "./runtime"
require "./totals"
@ -9,30 +8,17 @@ module Spectator::Formatting::Components
end
def to_s(io)
timing_line(io)
totals_line(io)
unless (failures = @report.failures).empty?
io.puts
failures_block(io, failures)
end
runtime(io)
totals(io)
end
private def timing_line(io)
private def runtime(io)
io << "Finished in "
io.puts Runtime.new(@report.runtime)
end
private def totals_line(io)
private def totals(io)
io.puts Totals.colorize(@report.counts)
end
private def failures_block(io, failures)
io.puts "Failed examples:"
io.puts
failures.each do |failure|
io.puts ExampleCommand.new(failure).colorize(:red)
end
end
end
end

View file

@ -43,7 +43,12 @@ module Spectator::Formatting
# Invoked after testing completes with summarized information from the test suite.
# Called after `#dump_failures` and before `#dump_profile`.
def dump_summary(notification)
io.puts Components::Stats.new(notification.report)
report = notification.report
io.puts Components::Stats.new(report)
return if (failures = report.failures).empty?
io.puts Components::FailureCommandList.new(failures)
end
# Invoked after testing completes with profiling information.