mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move formatter to config
This commit is contained in:
parent
23368f6183
commit
c73af72c7f
3 changed files with 36 additions and 9 deletions
|
@ -1,5 +1,11 @@
|
|||
module Spectator
|
||||
# Provides customization and describes specifics for how Spectator will run and report tests.
|
||||
class Config
|
||||
# Used to report test progress and results.
|
||||
getter formatter : Formatters::Formatter
|
||||
|
||||
# Creates a new configuration.
|
||||
def initialize(@formatter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
module Spectator
|
||||
# Mutable configuration used to produce a final configuration.
|
||||
# Use the setters in this class to incrementally build a configuration.
|
||||
# Then call `#build` to create the final configuration.
|
||||
class ConfigBuilder
|
||||
property formatter : Formatters::Formatter = Formatters::DefaultFormatter.new
|
||||
@formatter : Formatters::Formatter? = nil
|
||||
|
||||
def build
|
||||
Config.new
|
||||
# Sets the formatter to use for reporting test progress and results.
|
||||
def formatter=(formatter : Formatters::Formatter)
|
||||
@formatter = formatter
|
||||
end
|
||||
|
||||
# Retrieves the formatter to use.
|
||||
# If one wasn't specified by the user,
|
||||
# then `#default_formatter` is returned.
|
||||
private def formatter
|
||||
@formatter || default_formatter
|
||||
end
|
||||
|
||||
# The formatter that should be used,
|
||||
# if one wasn't provided.
|
||||
private def default_formatter
|
||||
Formatters::DefaultFormatter.new
|
||||
end
|
||||
|
||||
# Creates a configuration.
|
||||
def build : Config
|
||||
Config.new(formatter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,25 +1,24 @@
|
|||
module Spectator
|
||||
# Main driver for executing tests and feeding results to formatters.
|
||||
class Runner
|
||||
def initialize(@suite : TestSuite, config : Config)
|
||||
@formatter = Formatters::DefaultFormatter.new
|
||||
def initialize(@suite : TestSuite, @config : Config)
|
||||
end
|
||||
|
||||
def run : Nil
|
||||
results = [] of Result
|
||||
@formatter.start_suite
|
||||
@config.formatter.start_suite
|
||||
elapsed = Time.measure do
|
||||
results = @suite.map do |example|
|
||||
run_example(example)
|
||||
end
|
||||
end
|
||||
@formatter.end_suite(TestSuiteResults.new(results, elapsed))
|
||||
@config.formatter.end_suite(TestSuiteResults.new(results, elapsed))
|
||||
end
|
||||
|
||||
private def run_example(example)
|
||||
@formatter.start_example(example)
|
||||
@config.formatter.start_example(example)
|
||||
result = Internals::Harness.run(example)
|
||||
@formatter.end_example(result)
|
||||
@config.formatter.end_example(result)
|
||||
result
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue