Use @io instead of STDOUT

This commit is contained in:
Michael Miller 2019-02-15 23:10:08 -07:00
parent 49175e56ac
commit 04bccd162e

View file

@ -11,35 +11,35 @@ module Spectator::Formatters
# At the end, the totals and runtime are printed. # At the end, the totals and runtime are printed.
def end_suite(report) def end_suite(report)
failures = report.failures.map_with_index { |result, index| FailureBlock.new(index + 1, result) } failures = report.failures.map_with_index { |result, index| FailureBlock.new(index + 1, result) }
puts @io.puts
puts @io.puts
display_failures(failures) if failures.any? display_failures(failures) if failures.any?
display_stats(report) display_stats(report)
display_failure_commands(failures) if failures.any? display_failure_commands(failures) if failures.any?
end end
private def display_failures(failures) private def display_failures(failures)
puts "Failures:" @io.puts "Failures:"
puts @io.puts
failures.each do |block| failures.each do |block|
puts block @io.puts block
puts @io.puts
end end
end end
private def display_stats(report) private def display_stats(report)
puts "Finished in #{human_time(report.runtime)}" @io.puts "Finished in #{human_time(report.runtime)}"
puts "#{report.example_count} examples, #{report.failed_count} failures, #{report.error_count} errors, #{report.pending_count} pending" @io.puts "#{report.example_count} examples, #{report.failed_count} failures, #{report.error_count} errors, #{report.pending_count} pending"
end end
private def display_failure_commands(failures) private def display_failure_commands(failures)
puts @io.puts
puts "Failed examples:" @io.puts "Failed examples:"
puts @io.puts
failures.each do |block| failures.each do |block|
print "crystal spec " @io.print "crystal spec "
block.source(STDOUT) block.source(@io)
puts " # TODO" @io.puts " # TODO"
end end
end end