Some config cleanup

This commit is contained in:
Michael Miller 2020-10-17 21:39:41 -06:00
parent 79499c5d2e
commit b2bf980685
No known key found for this signature in database
GPG Key ID: F9A0C5C65B162436
3 changed files with 32 additions and 35 deletions

View File

@ -16,19 +16,16 @@ module Spectator
# Examples won't run, but the output will show that they did.
getter? dry_run : Bool
# Random number generator to use for everything.
getter random : Random
# Indicates whether tests are run in a random order.
# Indicates whether examples run in a random order.
getter? randomize : Bool
# Random seed used for number generation.
# Seed used for random number generation.
getter! random_seed : UInt64?
# Indicates whether profiling information should be displayed.
# Indicates whether timing information should be displayed.
getter? profile : Bool
# Filter that determines which examples to run.
# Filter determining examples to run.
getter example_filter : ExampleFilter
# Creates a new configuration.
@ -37,7 +34,6 @@ module Spectator
@fail_fast = builder.fail_fast?
@fail_blank = builder.fail_blank?
@dry_run = builder.dry_run?
@random = builder.random
@randomize = builder.randomize?
@random_seed = builder.seed?
@profile = builder.profile?

View File

@ -1,4 +1,5 @@
require "./composite_example_filter"
require "./config"
require "./example_filter"
require "./null_example_filter"
@ -12,14 +13,6 @@ module Spectator
new.build
end
# Random number generator to use.
protected getter random = Random::DEFAULT
def initialize
@seed = seed = @random.rand(UInt16).to_u64
@random.new_seed(seed)
end
@primary_formatter : Formatting::Formatter?
@additional_formatters = [] of Formatting::Formatter
@fail_fast = false
@ -29,6 +22,11 @@ module Spectator
@profile = false
@filters = [] of ExampleFilter
# Creates a configuration.
def build : Config
Config.new(self)
end
# Sets the primary formatter to use for reporting test progress and results.
def formatter=(formatter : Formatting::Formatter)
@primary_formatter = formatter
@ -105,7 +103,6 @@ module Spectator
# Sets the seed for the random number generator.
def seed=(seed)
@seed = seed
@random = Random.new(seed)
end
# Randomizes test execution order.
@ -153,10 +150,5 @@ module Spectator
CompositeExampleFilter.new(@filters)
end
end
# Creates a configuration.
def build : Config
Config.new(self)
end
end
end

View File

@ -30,6 +30,17 @@ module Spectator
@group_stack.push(root_group)
end
# Constructs the test spec.
# Returns the spec instance.
#
# Raises an error if there were not symmetrical calls to `#start_group` and `#end_group`.
# This would indicate a logical error somewhere in Spectator or an extension of it.
def build : Spec
raise "Mismatched start and end groups" unless root?
Spec.new(root_group, config)
end
# Defines a new example group and pushes it onto the group stack.
# Examples and groups defined after calling this method will be nested under the new group.
# The group will be finished and popped off the stack when `#end_example` is called.
@ -87,23 +98,21 @@ module Spectator
# The example is added to the current group by `Example` initializer.
end
# Builds the configuration to use for the spec.
# A `ConfigBuilder` is yielded to the block provided to this method.
# That builder will be used to create the configuration.
def config
builder = ConfigBuilder.new
yield builder
@config = builder.build
end
# Sets the configuration of the spec.
# This configuration controls how examples run.
def config=(config)
@config = config
end
# Constructs the test spec.
# Returns the spec instance.
#
# Raises an error if there were not symmetrical calls to `#start_group` and `#end_group`.
# This would indicate a logical error somewhere in Spectator or an extension of it.
def build : Spec
raise "Mismatched start and end groups" unless root?
Spec.new(root_group, config)
end
# Checks if the current group is the root group.
private def root?
@group_stack.size == 1
@ -122,8 +131,8 @@ module Spectator
# Retrieves the configuration.
# If one wasn't previously set, a default configuration is used.
private def config
@config || ConfigBuilder.new.build
private def config : Config
@config || ConfigBuilder.default
end
end
end