Allow output to be printed to other streams

This commit is contained in:
Michael Miller 2019-02-15 22:12:18 -07:00
parent 2012db85c5
commit e8ca350152

View file

@ -22,6 +22,11 @@ module Spectator::Formatters
# Character output for a pending or skipped example. # Character output for a pending or skipped example.
PENDING_CHAR = '*' PENDING_CHAR = '*'
# Creates the formatter.
# By default, output is sent to `STDOUT`.
def initialize(@io : IO = STDOUT)
end
# Does nothing when an example is started. # Does nothing when an example is started.
def start_example(example) def start_example(example)
# ... # ...
@ -31,13 +36,13 @@ module Spectator::Formatters
def end_example(result) def end_example(result)
case result case result
when ErroredResult when ErroredResult
print error(ERROR_CHAR) @io.print error(ERROR_CHAR)
when PendingResult when PendingResult
print pending(PENDING_CHAR) @io.print pending(PENDING_CHAR)
when SuccessfulResult when SuccessfulResult
print success(SUCCESS_CHAR) @io.print success(SUCCESS_CHAR)
else # FailedResult else # FailedResult
print failure(FAILURE_CHAR) @io.print failure(FAILURE_CHAR)
end end
end end
end end