diff --git a/src/spectator/formatters/comment.cr b/src/spectator/formatters/comment.cr new file mode 100644 index 0000000..fdb0237 --- /dev/null +++ b/src/spectator/formatters/comment.cr @@ -0,0 +1,20 @@ +module Spectator::Formatters + # Produces a stringified comment for output. + private struct Comment(T) + # Creates the comment. + def initialize(@text : T) + end + + # Appends the comment to the output. + def to_s(io) + io << '#' + io << ' ' + io << @text + end + + # Creates a colorized version of the comment. + def self.color(text : T) forall T + Color.comment(new(text)) + end + end +end diff --git a/src/spectator/formatters/failure_block.cr b/src/spectator/formatters/failure_block.cr index 1c2677f..2cbf334 100644 --- a/src/spectator/formatters/failure_block.cr +++ b/src/spectator/formatters/failure_block.cr @@ -77,9 +77,7 @@ module Spectator::Formatters private def source(io) INITIAL_INDENT.times { io << ' ' } (@index_length + 2).times { io << ' ' } # +2 for ) and space. - io << '#' - io << ' ' - io << Color.comment(@result.example.source) + io << Comment.color(@result.example.source) end # Gets the number of characters a positive integer spans in base 10. diff --git a/src/spectator/formatters/suite_summary.cr b/src/spectator/formatters/suite_summary.cr index 9be8b27..0f08db1 100644 --- a/src/spectator/formatters/suite_summary.cr +++ b/src/spectator/formatters/suite_summary.cr @@ -47,7 +47,8 @@ module Spectator::Formatters failures.each do |result| @io.print "crystal spec " result.example.source.to_s(@io) - @io.puts " # TODO" + @io << ' ' + @io.puts Comment.color("TODO") end end