mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial code for reporters
This commit is contained in:
parent
aba9f50d58
commit
e38fddb12a
5 changed files with 53 additions and 4 deletions
|
@ -12,10 +12,9 @@ module Spectator
|
||||||
DSL.describe({{what}}) {{block}}
|
DSL.describe({{what}}) {{block}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
{% debug %}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
at_exit do
|
at_exit do
|
||||||
Runner.new(ALL_EXAMPLES, DefinedRunOrder.new).run
|
Runner.new(ALL_EXAMPLES).run
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
6
src/spectator/reporters.cr
Normal file
6
src/spectator/reporters.cr
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
require "./reporters/*"
|
||||||
|
|
||||||
|
module Spectator
|
||||||
|
module Reporters
|
||||||
|
end
|
||||||
|
end
|
10
src/spectator/reporters/reporter.cr
Normal file
10
src/spectator/reporters/reporter.cr
Normal 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
|
29
src/spectator/reporters/standard_reporter.cr
Normal file
29
src/spectator/reporters/standard_reporter.cr
Normal 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
|
|
@ -3,14 +3,19 @@ require "./successful_example_result"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
class Runner
|
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
|
end
|
||||||
|
|
||||||
def run : Nil
|
def run : Nil
|
||||||
|
@reporter.start_suite
|
||||||
sorted_examples.each do |example|
|
sorted_examples.each do |example|
|
||||||
|
@reporter.start_example(example)
|
||||||
result = run_example(example)
|
result = run_example(example)
|
||||||
pp result
|
@reporter.end_example(result)
|
||||||
end
|
end
|
||||||
|
@reporter.end_suite
|
||||||
end
|
end
|
||||||
|
|
||||||
private def sorted_examples
|
private def sorted_examples
|
||||||
|
|
Loading…
Reference in a new issue