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.
|
# Builds the tests and runs the framework.
|
||||||
private def run
|
private def run
|
||||||
# Build the test spec and run it.
|
# Build the spec and run it.
|
||||||
spec = ::Spectator::DSL::Builder.build
|
# DSL::Builder.config = config # TODO: Set config.
|
||||||
|
spec = DSL::Builder.build
|
||||||
spec.run
|
spec.run
|
||||||
true
|
true
|
||||||
rescue ex
|
rescue ex
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
require "./composite_example_filter"
|
||||||
|
require "./example_filter"
|
||||||
|
require "./null_example_filter"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
# Mutable configuration used to produce a final configuration.
|
# Mutable configuration used to produce a final configuration.
|
||||||
# Use the setters in this class to incrementally build a configuration.
|
# Use the setters in this class to incrementally build a configuration.
|
||||||
|
|
|
@ -35,6 +35,13 @@ module Spectator::DSL
|
||||||
@@builder.add_example(*args, &block)
|
@@builder.add_example(*args, &block)
|
||||||
end
|
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.
|
# Constructs the test spec.
|
||||||
# Returns the spec instance.
|
# Returns the spec instance.
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
require "./config"
|
||||||
require "./example"
|
require "./example"
|
||||||
require "./example_group"
|
require "./example_group"
|
||||||
require "./example_iterator"
|
require "./example_iterator"
|
||||||
|
@ -5,14 +6,28 @@ require "./example_iterator"
|
||||||
module Spectator
|
module Spectator
|
||||||
# Contains examples to be tested.
|
# Contains examples to be tested.
|
||||||
class Spec
|
class Spec
|
||||||
def initialize(@root : ExampleGroup)
|
def initialize(@root : ExampleGroup, @config : Config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
examples = ExampleIterator.new(@root).to_a
|
|
||||||
Runner.new(examples).run
|
Runner.new(examples).run
|
||||||
end
|
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
|
private struct Runner
|
||||||
def initialize(@examples : Array(Example))
|
def initialize(@examples : Array(Example))
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require "./config"
|
||||||
|
require "./config_builder"
|
||||||
require "./example"
|
require "./example"
|
||||||
require "./example_context_method"
|
require "./example_context_method"
|
||||||
require "./example_group"
|
require "./example_group"
|
||||||
|
@ -17,6 +19,9 @@ module Spectator
|
||||||
# New examples should be added to the current group.
|
# New examples should be added to the current group.
|
||||||
@group_stack : Deque(ExampleGroup)
|
@group_stack : Deque(ExampleGroup)
|
||||||
|
|
||||||
|
# Configuration for the spec.
|
||||||
|
@config : Config?
|
||||||
|
|
||||||
# Creates a new spec builder.
|
# Creates a new spec builder.
|
||||||
# A root group is pushed onto the group stack.
|
# A root group is pushed onto the group stack.
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -82,6 +87,12 @@ module Spectator
|
||||||
# The example is added to the current group by `Example` initializer.
|
# The example is added to the current group by `Example` initializer.
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Sets the configuration of the spec.
|
||||||
|
# This configuration controls how examples run.
|
||||||
|
def config=(config)
|
||||||
|
@config = config
|
||||||
|
end
|
||||||
|
|
||||||
# Constructs the test spec.
|
# Constructs the test spec.
|
||||||
# Returns the spec instance.
|
# Returns the spec instance.
|
||||||
#
|
#
|
||||||
|
@ -90,7 +101,7 @@ module Spectator
|
||||||
def build : Spec
|
def build : Spec
|
||||||
raise "Mismatched start and end groups" unless root?
|
raise "Mismatched start and end groups" unless root?
|
||||||
|
|
||||||
Spec.new(root_group)
|
Spec.new(root_group, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if the current group is the root group.
|
# Checks if the current group is the root group.
|
||||||
|
@ -108,5 +119,11 @@ module Spectator
|
||||||
private def current_group
|
private def current_group
|
||||||
@group_stack.last
|
@group_stack.last
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue