diff --git a/src/spectator/formatters/failure_command.cr b/src/spectator/formatters/failure_command.cr new file mode 100644 index 0000000..b0993af --- /dev/null +++ b/src/spectator/formatters/failure_command.cr @@ -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 diff --git a/src/spectator/formatters/suite_summary.cr b/src/spectator/formatters/suite_summary.cr index c5f0e52..0ce12fd 100644 --- a/src/spectator/formatters/suite_summary.cr +++ b/src/spectator/formatters/suite_summary.cr @@ -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