mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add config to spec builder
This commit is contained in:
parent
4462f27316
commit
79499c5d2e
5 changed files with 49 additions and 5 deletions
|
@ -91,8 +91,9 @@ module Spectator
|
|||
|
||||
# Builds the tests and runs the framework.
|
||||
private def run
|
||||
# Build the test spec and run it.
|
||||
spec = ::Spectator::DSL::Builder.build
|
||||
# Build the spec and run it.
|
||||
# DSL::Builder.config = config # TODO: Set config.
|
||||
spec = DSL::Builder.build
|
||||
spec.run
|
||||
true
|
||||
rescue ex
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
require "./composite_example_filter"
|
||||
require "./example_filter"
|
||||
require "./null_example_filter"
|
||||
|
||||
module Spectator
|
||||
# Mutable configuration used to produce a final configuration.
|
||||
# Use the setters in this class to incrementally build a configuration.
|
||||
|
|
|
@ -35,6 +35,13 @@ module Spectator::DSL
|
|||
@@builder.add_example(*args, &block)
|
||||
end
|
||||
|
||||
# Sets the configuration of the spec.
|
||||
#
|
||||
# See `Spec::Builder#config=` for usage details.
|
||||
def config=(config)
|
||||
@@builder.config = config
|
||||
end
|
||||
|
||||
# Constructs the test spec.
|
||||
# Returns the spec instance.
|
||||
#
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require "./config"
|
||||
require "./example"
|
||||
require "./example_group"
|
||||
require "./example_iterator"
|
||||
|
@ -5,14 +6,28 @@ require "./example_iterator"
|
|||
module Spectator
|
||||
# Contains examples to be tested.
|
||||
class Spec
|
||||
def initialize(@root : ExampleGroup)
|
||||
def initialize(@root : ExampleGroup, @config : Config)
|
||||
end
|
||||
|
||||
def run
|
||||
examples = ExampleIterator.new(@root).to_a
|
||||
Runner.new(examples).run
|
||||
end
|
||||
|
||||
# Generates a list of examples to run.
|
||||
# The order of the examples are also sorted based on the configuration.
|
||||
private def examples
|
||||
ExampleIterator.new(@root).to_a.tap do |examples|
|
||||
if @config.randomize?
|
||||
random = if (seed = @config.random_seed)
|
||||
Random.new(seed)
|
||||
else
|
||||
Random.new
|
||||
end
|
||||
examples.shuffle!(random)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private struct Runner
|
||||
def initialize(@examples : Array(Example))
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require "./config"
|
||||
require "./config_builder"
|
||||
require "./example"
|
||||
require "./example_context_method"
|
||||
require "./example_group"
|
||||
|
@ -17,6 +19,9 @@ module Spectator
|
|||
# New examples should be added to the current group.
|
||||
@group_stack : Deque(ExampleGroup)
|
||||
|
||||
# Configuration for the spec.
|
||||
@config : Config?
|
||||
|
||||
# Creates a new spec builder.
|
||||
# A root group is pushed onto the group stack.
|
||||
def initialize
|
||||
|
@ -82,6 +87,12 @@ module Spectator
|
|||
# The example is added to the current group by `Example` initializer.
|
||||
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.
|
||||
#
|
||||
|
@ -90,7 +101,7 @@ module Spectator
|
|||
def build : Spec
|
||||
raise "Mismatched start and end groups" unless root?
|
||||
|
||||
Spec.new(root_group)
|
||||
Spec.new(root_group, config)
|
||||
end
|
||||
|
||||
# Checks if the current group is the root group.
|
||||
|
@ -108,5 +119,11 @@ module Spectator
|
|||
private def current_group
|
||||
@group_stack.last
|
||||
end
|
||||
|
||||
# Retrieves the configuration.
|
||||
# If one wasn't previously set, a default configuration is used.
|
||||
private def config
|
||||
@config || ConfigBuilder.new.build
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue