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
|
module Spectator::Formatters
|
||||||
# Mix-in that provides methods for colorizing output.
|
# Method for colorizing output.
|
||||||
module Color
|
module Color
|
||||||
|
extend self
|
||||||
|
|
||||||
# Symbol in `Colorize` representing success.
|
# Symbol in `Colorize` representing success.
|
||||||
SUCCESS_COLOR = :green
|
SUCCESS_COLOR = :green
|
||||||
|
|
||||||
|
@ -14,22 +16,22 @@ module Spectator::Formatters
|
||||||
PENDING_COLOR = :yellow
|
PENDING_COLOR = :yellow
|
||||||
|
|
||||||
# Colorizes some text with the success color.
|
# Colorizes some text with the success color.
|
||||||
private def success(text)
|
def success(text)
|
||||||
text.colorize(SUCCESS_COLOR)
|
text.colorize(SUCCESS_COLOR)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Colorizes some text with the failure color.
|
# Colorizes some text with the failure color.
|
||||||
private def failure(text)
|
def failure(text)
|
||||||
text.colorize(FAILURE_COLOR)
|
text.colorize(FAILURE_COLOR)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Colorizes some text with the error color.
|
# Colorizes some text with the error color.
|
||||||
private def error(text)
|
def error(text)
|
||||||
text.colorize(ERROR_COLOR)
|
text.colorize(ERROR_COLOR)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Colorizes some text with the pending/skipped color.
|
# Colorizes some text with the pending/skipped color.
|
||||||
private def pending(text)
|
def pending(text)
|
||||||
text.colorize(PENDING_COLOR)
|
text.colorize(PENDING_COLOR)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,19 +8,6 @@ module Spectator::Formatters
|
||||||
# At the end of the test suite, a summary of failures and results is displayed.
|
# At the end of the test suite, a summary of failures and results is displayed.
|
||||||
class DotsFormatter < Formatter
|
class DotsFormatter < Formatter
|
||||||
include SuiteSummary
|
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.
|
# Creates the formatter.
|
||||||
# By default, output is sent to `STDOUT`.
|
# By default, output is sent to `STDOUT`.
|
||||||
|
@ -34,15 +21,31 @@ module Spectator::Formatters
|
||||||
|
|
||||||
# Produces a single character output based on a result.
|
# Produces a single character output based on a result.
|
||||||
def end_example(result)
|
def end_example(result)
|
||||||
case result
|
@io.print result.call(Character)
|
||||||
when ErroredResult
|
end
|
||||||
@io.print error(ERROR_CHAR)
|
|
||||||
when PendingResult
|
# Interface for `Result` to pick a character for output.
|
||||||
@io.print pending(PENDING_CHAR)
|
private module Character
|
||||||
when SuccessfulResult
|
extend self
|
||||||
@io.print success(SUCCESS_CHAR)
|
|
||||||
else # FailedResult
|
# Character output for a successful example.
|
||||||
@io.print failure(FAILURE_CHAR)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue