mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial code for refactoring formatters
This commit is contained in:
parent
88c32b697b
commit
2012db85c5
4 changed files with 97 additions and 1 deletions
|
@ -25,7 +25,7 @@ module Spectator
|
||||||
# The formatter that should be used,
|
# The formatter that should be used,
|
||||||
# if one wasn't provided.
|
# if one wasn't provided.
|
||||||
private def default_formatter
|
private def default_formatter
|
||||||
Formatters::DefaultFormatter.new
|
Formatters::DotsFormatter.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a configuration.
|
# Creates a configuration.
|
||||||
|
|
36
src/spectator/formatters/color.cr
Normal file
36
src/spectator/formatters/color.cr
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
module Spectator::Formatters
|
||||||
|
# Mix-in that provides methods for colorizing output.
|
||||||
|
module Color
|
||||||
|
# Symbol in `Colorize` representing success.
|
||||||
|
SUCCESS_COLOR = :green
|
||||||
|
|
||||||
|
# Symbol in `Colorize` representing failure.
|
||||||
|
FAILURE_COLOR = :red
|
||||||
|
|
||||||
|
# Symbol in `Colorize` representing an error.
|
||||||
|
ERROR_COLOR = :magenta
|
||||||
|
|
||||||
|
# Symbol in `Colorize` representing pending or skipped.
|
||||||
|
PENDING_COLOR = :yellow
|
||||||
|
|
||||||
|
# Colorizes some text with the success color.
|
||||||
|
private def success(text)
|
||||||
|
text.colorize(SUCCESS_COLOR)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Colorizes some text with the failure color.
|
||||||
|
private def failure(text)
|
||||||
|
text.colorize(FAILURE_COLOR)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Colorizes some text with the error color.
|
||||||
|
private def error(text)
|
||||||
|
text.colorize(ERROR_COLOR)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Colorizes some text with the pending/skipped color.
|
||||||
|
private def pending(text)
|
||||||
|
text.colorize(PENDING_COLOR)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
44
src/spectator/formatters/dots_formatter.cr
Normal file
44
src/spectator/formatters/dots_formatter.cr
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
require "./formatter"
|
||||||
|
require "./suite_summary"
|
||||||
|
|
||||||
|
module Spectator::Formatters
|
||||||
|
# Produces a single character for each example.
|
||||||
|
# A dot is output for each successful example (hence the name).
|
||||||
|
# Other characters are output for non-successful results.
|
||||||
|
# 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 = '*'
|
||||||
|
|
||||||
|
# Does nothing when an example is started.
|
||||||
|
def start_example(example)
|
||||||
|
# ...
|
||||||
|
end
|
||||||
|
|
||||||
|
# Produces a single character output based on a result.
|
||||||
|
def end_example(result)
|
||||||
|
case result
|
||||||
|
when ErroredResult
|
||||||
|
print error(ERROR_CHAR)
|
||||||
|
when PendingResult
|
||||||
|
print pending(PENDING_CHAR)
|
||||||
|
when SuccessfulResult
|
||||||
|
print success(SUCCESS_CHAR)
|
||||||
|
else # FailedResult
|
||||||
|
print failure(FAILURE_CHAR)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
16
src/spectator/formatters/suite_summary.cr
Normal file
16
src/spectator/formatters/suite_summary.cr
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
module Spectator::Formatters
|
||||||
|
# Mix-in for producing a human-readable summary of a test suite.
|
||||||
|
module SuiteSummary
|
||||||
|
# Does nothing when starting a test suite.
|
||||||
|
def start_suite(suite)
|
||||||
|
# ...
|
||||||
|
end
|
||||||
|
|
||||||
|
# Produces the summary of test suite from a report.
|
||||||
|
# A block describing each failure is displayed.
|
||||||
|
# At the end, the totals and runtime are printed.
|
||||||
|
def end_suite(report)
|
||||||
|
raise NotImplementedError.new("SuiteSummary#end_suite")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue