mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use Result#call instead of case-statement
Color module is no longer mixed-in.
This commit is contained in:
parent
6a8d447570
commit
11c738b941
2 changed files with 32 additions and 27 deletions
|
@ -1,6 +1,8 @@
|
|||
module Spectator::Formatters
|
||||
# Mix-in that provides methods for colorizing output.
|
||||
# Method for colorizing output.
|
||||
module Color
|
||||
extend self
|
||||
|
||||
# Symbol in `Colorize` representing success.
|
||||
SUCCESS_COLOR = :green
|
||||
|
||||
|
@ -14,22 +16,22 @@ module Spectator::Formatters
|
|||
PENDING_COLOR = :yellow
|
||||
|
||||
# Colorizes some text with the success color.
|
||||
private def success(text)
|
||||
def success(text)
|
||||
text.colorize(SUCCESS_COLOR)
|
||||
end
|
||||
|
||||
# Colorizes some text with the failure color.
|
||||
private def failure(text)
|
||||
def failure(text)
|
||||
text.colorize(FAILURE_COLOR)
|
||||
end
|
||||
|
||||
# Colorizes some text with the error color.
|
||||
private def error(text)
|
||||
def error(text)
|
||||
text.colorize(ERROR_COLOR)
|
||||
end
|
||||
|
||||
# Colorizes some text with the pending/skipped color.
|
||||
private def pending(text)
|
||||
def pending(text)
|
||||
text.colorize(PENDING_COLOR)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,19 +8,6 @@ module Spectator::Formatters
|
|||
# At the end of the test suite, a summary of failures and results is displayed.
|
||||
class DotsFormatter < Formatter
|
||||
include SuiteSummary
|
||||
include Color
|
||||
|
||||
# Character output for a successful example.
|
||||
SUCCESS_CHAR = '.'
|
||||
|
||||
# Character output for a failed example.
|
||||
FAILURE_CHAR = 'F'
|
||||
|
||||
# Character output for an errored example.
|
||||
ERROR_CHAR = 'E'
|
||||
|
||||
# Character output for a pending or skipped example.
|
||||
PENDING_CHAR = '*'
|
||||
|
||||
# Creates the formatter.
|
||||
# By default, output is sent to `STDOUT`.
|
||||
|
@ -34,15 +21,31 @@ module Spectator::Formatters
|
|||
|
||||
# Produces a single character output based on a result.
|
||||
def end_example(result)
|
||||
case result
|
||||
when ErroredResult
|
||||
@io.print error(ERROR_CHAR)
|
||||
when PendingResult
|
||||
@io.print pending(PENDING_CHAR)
|
||||
when SuccessfulResult
|
||||
@io.print success(SUCCESS_CHAR)
|
||||
else # FailedResult
|
||||
@io.print failure(FAILURE_CHAR)
|
||||
@io.print result.call(Character)
|
||||
end
|
||||
|
||||
# Interface for `Result` to pick a character for output.
|
||||
private module Character
|
||||
extend self
|
||||
|
||||
# Character output for a successful example.
|
||||
def success(result)
|
||||
Color.success('.')
|
||||
end
|
||||
|
||||
# Character output for a failed example.
|
||||
def failure(result)
|
||||
Color.failure('F')
|
||||
end
|
||||
|
||||
# Character output for an errored example.
|
||||
def error(result)
|
||||
Color.error('E')
|
||||
end
|
||||
|
||||
# Character output for a pending or skipped example.
|
||||
def pending(result)
|
||||
Color.pending('*')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue