Cleanup color code

This commit is contained in:
Michael Miller 2018-09-15 14:04:17 -06:00
parent 625262b6d5
commit caeab6c338

View file

@ -4,6 +4,16 @@ require "colorize"
module Spectator module Spectator
module Formatters module Formatters
class DefaultFormatter < Formatter class DefaultFormatter < Formatter
SUCCESS_COLOR = :green
FAILURE_COLOR = :red
ERROR_COLOR = :magenta
PENDING_COLOR = :yellow
SUCCESS_CHAR = '.'.colorize(SUCCESS_COLOR)
FAILURE_CHAR = 'F'.colorize(FAILURE_COLOR)
ERROR_CHAR = 'E'.colorize(ERROR_COLOR)
PENDING_CHAR = 'P'.colorize(PENDING_COLOR)
def start_suite def start_suite
end end
@ -18,15 +28,19 @@ module Spectator
end end
def end_example(result : Result) def end_example(result : Result)
print case result print result_char(result)
end
private def result_char(result : Result)
case result
when SuccessfulResult when SuccessfulResult
".".colorize.green SUCCESS_CHAR
when PendingResult when PendingResult
"P".colorize.yellow PENDING_CHAR
when ErroredResult when ErroredResult
"E".colorize.magenta ERROR_CHAR
when FailedResult when FailedResult
"F".colorize.red FAILURE_CHAR
end end
end end
@ -41,11 +55,11 @@ module Spectator
pending = results.pending_examples pending = results.pending_examples
string = "#{examples} examples, #{failures} failures, #{errors} errors, #{pending} pending" string = "#{examples} examples, #{failures} failures, #{errors} errors, #{pending} pending"
if failures > 0 || errors > 0 if failures > 0 || errors > 0
string.colorize.red string.colorize(FAILURE_COLOR)
elsif pending != examples elsif pending != examples
string.colorize.yellow string.colorize(PENDING_COLOR)
else else
string.colorize.green string.colorize(SUCCESS_COLOR)
end end
end end