Structure for applying configuration

This commit is contained in:
Michael Miller 2018-12-13 13:50:59 -07:00
parent 9527427b45
commit 23368f6183
6 changed files with 84 additions and 5 deletions

View file

@ -0,0 +1,16 @@
module Spectator
# Generates configuration from the command-line arguments.
class CommandLineArgumentsConfigSource < ConfigSource
# Creates the configuration source.
# By default, the command-line arguments (ARGV) are used.
# But custom arguments can be passed in.
def initialize(@args : Array(String) = ARGV)
end
# Applies the specified configuration to a builder.
# Calling this method from multiple sources builds up the final configuration.
def apply_to(builder : ConfigBuilder) : Nil
# ...
end
end
end

View file

@ -0,0 +1,9 @@
module Spectator
class ConfigBuilder
property formatter : Formatters::Formatter = Formatters::DefaultFormatter.new
def build
Config.new
end
end
end

View file

@ -0,0 +1,8 @@
module Spectator
# Interface for all places that configuration can originate.
abstract class ConfigSource
# Applies the specified configuration to a builder.
# Calling this method from multiple sources builds up the final configuration.
abstract def apply_to(builder : ConfigBuilder) : Nil
end
end

View file

@ -23,9 +23,13 @@ require "./example_group"
require "./nested_example_group"
require "./root_example_group"
require "./config"
require "./config_builder"
require "./config_source"
require "./command_line_arguments_config_source"
require "./example_failed"
require "./expectation_failed"
require "./config"
require "./test_suite"
require "./test_suite_results"
require "./runner"

View file

@ -1,8 +1,8 @@
module Spectator
# Main driver for executing tests and feeding results to formatters.
class Runner
def initialize(@suite : TestSuite,
@formatter : Formatters::Formatter = Formatters::DefaultFormatter.new)
def initialize(@suite : TestSuite, config : Config)
@formatter = Formatters::DefaultFormatter.new
end
def run : Nil