Move failure command it's own type

This commit is contained in:
Michael Miller 2019-02-22 16:43:25 -07:00
parent e92b1dc466
commit 487726ea54
2 changed files with 23 additions and 6 deletions

View File

@ -0,0 +1,19 @@
module Spectator::Formatters
# Produces a stringified command to run a failed test.
private struct FailureCommand
# Creates the failure command.
def initialize(@example : Example)
end
# Appends the command to the output.
def to_s(io)
io << "crystal spec "
io << @example.source
end
# Colorizes the command instance based on the result.
def self.color(result)
result.call(Color) { new(result.example) }
end
end
end

View File

@ -10,12 +10,11 @@ module Spectator::Formatters
# A block describing each failure is displayed.
# At the end, the totals and runtime are printed.
def end_suite(report)
failed = report.failed_count > 0
@io.puts
@io.puts
failures(report.failures) if failed
failures(report.failures) if report.failed?
stats(report)
failure_commands(report.failures) if failed
failure_commands(report.failures) if report.failed?
end
# Produces the failure section of the summary.
@ -44,10 +43,9 @@ module Spectator::Formatters
@io.puts "Failed examples:"
@io.puts
failures.each do |result|
@io.print "crystal spec "
result.example.source.to_s(@io)
@io << FailureCommand.color(result)
@io << ' '
@io.puts Comment.color("TODO")
@io.puts Comment.color(result.example)
end
end
end