Initial code for reporters

This commit is contained in:
Michael Miller 2018-08-30 22:21:10 -06:00
parent aba9f50d58
commit e38fddb12a
5 changed files with 53 additions and 4 deletions

View File

@ -12,10 +12,9 @@ module Spectator
DSL.describe({{what}}) {{block}}
end
end
{% debug %}
end
at_exit do
Runner.new(ALL_EXAMPLES, DefinedRunOrder.new).run
Runner.new(ALL_EXAMPLES).run
end
end

View File

@ -0,0 +1,6 @@
require "./reporters/*"
module Spectator
module Reporters
end
end

View File

@ -0,0 +1,10 @@
module Spectator
module Reporters
abstract class Reporter
abstract def start_suite
abstract def end_suite
abstract def start_example(example : Example)
abstract def end_example(result : ExampleResult)
end
end
end

View File

@ -0,0 +1,29 @@
require "./reporter"
require "colorize"
module Spectator
module Reporters
class StandardReporter < Reporter
def start_suite
end
def end_suite
puts
end
def start_example(example : Example)
end
def end_example(result : ExampleResult)
print case result
when SuccessfulExampleResult
".".colorize.green
when ErroredExampleResult
"E".colorize.magenta
when FailedExampleResult
"F".colorize.red
end
end
end
end
end

View File

@ -3,14 +3,19 @@ require "./successful_example_result"
module Spectator
class Runner
def initialize(@examples : Enumerable(Example), @run_order : RunOrder)
def initialize(@examples : Enumerable(Example),
@run_order : RunOrder = DefinedRunOrder.new,
@reporter : Reporters::Reporter = Reporters::StandardReporter.new)
end
def run : Nil
@reporter.start_suite
sorted_examples.each do |example|
@reporter.start_example(example)
result = run_example(example)
pp result
@reporter.end_example(result)
end
@reporter.end_suite
end
private def sorted_examples