Shuffle code around for runner

This commit is contained in:
Michael Miller 2018-12-12 15:22:56 -07:00
parent c29748ede5
commit 6c5da5a703
3 changed files with 28 additions and 10 deletions

View file

@ -76,7 +76,8 @@ module Spectator
private def self.run
# Build the root-level example group and run it.
group = ::Spectator::DSL::Builder.build
Runner.new(group).run
suite = ::Spectator::TestSuite.new(group)
Runner.new(suite).run
rescue ex
# Catch all unhandled exceptions here.
# Examples are already wrapped, so any exceptions they throw are caught.

View file

@ -1,23 +1,26 @@
module Spectator
# Main driver for executing tests and feeding results to formatters.
class Runner
def initialize(@group : ExampleGroup,
def initialize(@suite : TestSuite,
@formatter : Formatters::Formatter = Formatters::DefaultFormatter.new)
end
def run : Nil
iterator = ExampleIterator.new(@group)
results = [] of Result
elapsed = Time.measure do
@formatter.start_suite
results = iterator.map do |example|
@formatter.start_example(example)
Internals::Harness.run(example).tap do |result|
@formatter.end_example(result)
end.as(Result)
end.to_a
elapsed = Time.measure do
results = @suite.map do |example|
run_example(example)
end
end
@formatter.end_suite(TestSuiteResults.new(results, elapsed))
end
private def run_example(example)
@formatter.start_example(example)
result = Internals::Harness.run(example)
@formatter.end_example(result)
result
end
end
end

View file

@ -1,5 +1,19 @@
module Spectator
# Encapsulates the tests to run and additional properties about them.
class TestSuite
include Enumerable(Example)
def initialize(@group : ExampleGroup)
end
def each
iterator.each do |example|
yield example
end
end
private def iterator
ExampleIterator.new(@group)
end
end
end