diff --git a/src/spec/context.cr b/src/spec/context.cr index 1cc473819580..2cc613dec392 100644 --- a/src/spec/context.cr +++ b/src/spec/context.cr @@ -116,6 +116,24 @@ module Spec Fail Error Pending + + def color : Colorize::Color + case self + in Success then Colorize::ColorANSI::Green + in Fail then Colorize::ColorANSI::Red + in Error then Colorize::ColorANSI::Red + in Pending then Colorize::ColorANSI::Yellow + end + end + + def letter : Char + case self + in Success then '.' + in Fail then 'F' + in Error then 'E' + in Pending then '*' + end + end end # :nodoc: diff --git a/src/spec/dsl.cr b/src/spec/dsl.cr index d712aa59da4f..32875c68a305 100644 --- a/src/spec/dsl.cr +++ b/src/spec/dsl.cr @@ -11,36 +11,20 @@ module Spec Comment Focus Order - end - private STATUS_COLORS = { - Status::Success => :green, - Status::Fail => :red, - Status::Error => :red, - Status::Pending => :yellow, - } - - private INFO_COLORS = { - InfoKind::Comment => :cyan, - InfoKind::Focus => :cyan, - InfoKind::Order => :cyan, - } - - private LETTERS = { - Status::Success => '.', - Status::Fail => 'F', - Status::Error => 'E', - Status::Pending => '*', - } + def color : Colorize::Color + Colorize::ColorANSI::Cyan + end + end # :nodoc: def self.color(str, status : Status) - str.colorize(STATUS_COLORS[status]) + str.colorize(status.color) end # :nodoc: def self.color(str, kind : InfoKind) - str.colorize(INFO_COLORS[kind]) + str.colorize(kind.color) end # :nodoc: diff --git a/src/spec/formatter.cr b/src/spec/formatter.cr index b7256f80971f..45651f61cfd4 100644 --- a/src/spec/formatter.cr +++ b/src/spec/formatter.cr @@ -38,7 +38,7 @@ module Spec end def report(result) - @io << Spec.color(LETTERS[result.kind], result.kind) + @io << Spec.color(result.kind.letter, result.kind) split_lines @io.flush end