mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove TestSuite middle-man object
This commit is contained in:
parent
e7138080a6
commit
f09a6a87e5
3 changed files with 26 additions and 47 deletions
|
@ -1,19 +1,28 @@
|
|||
require "./config"
|
||||
require "./example"
|
||||
require "./example_group"
|
||||
require "./test_suite"
|
||||
require "./spec/*"
|
||||
|
||||
module Spectator
|
||||
# Contains examples to be tested.
|
||||
# Contains examples to be tested and configuration for running them.
|
||||
class Spec
|
||||
# Creates the spec.
|
||||
# The *root* is the top-most example group.
|
||||
# All examples in this group and groups nested under are candidates for execution.
|
||||
# The *config* provides settings controlling how tests will be executed.
|
||||
def initialize(@root : ExampleGroup, @config : Config)
|
||||
end
|
||||
|
||||
def run(filter : ExampleFilter)
|
||||
suite = TestSuite.new(@root, filter)
|
||||
Runner.new(suite, @config).run
|
||||
# Runs all selected examples and returns the results.
|
||||
def run
|
||||
Runner.new(examples, @config).run
|
||||
end
|
||||
|
||||
# Selects and shuffles the examples that should run.
|
||||
private def examples
|
||||
iterator = @config.iterator(@root)
|
||||
iterator.to_a.tap do |examples|
|
||||
@config.shuffle!(examples)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
require "./spec/*"
|
||||
|
|
|
@ -2,14 +2,18 @@ require "../example"
|
|||
|
||||
module Spectator
|
||||
class Spec
|
||||
# Logic for executing examples and collecting results.
|
||||
private struct Runner
|
||||
def initialize(@suite : TestSuite, @config : Config)
|
||||
# Creates the runner.
|
||||
# The collection of *examples* should be pre-filtered and shuffled.
|
||||
# This runner will run each example in the order provided.
|
||||
def initialize(@examples : Enumerable(Example), @config : Config)
|
||||
end
|
||||
|
||||
# Runs the test suite.
|
||||
# This will run the selected examples
|
||||
# and invoke the formatter to output results.
|
||||
# True will be returned if the test suite ran successfully,
|
||||
# Runs the spec.
|
||||
# This will run the provided examples
|
||||
# and invoke the reporters to communicate results.
|
||||
# True will be returned if the spec ran successfully,
|
||||
# or false if there was at least one failure.
|
||||
def run : Bool
|
||||
# Indicate the suite is starting.
|
||||
|
@ -42,15 +46,6 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
# Retrieves an enumerable for the examples to run.
|
||||
# The order of examples is randomized
|
||||
# if specified by the configuration.
|
||||
private def example_order
|
||||
@suite.to_a.tap do |examples|
|
||||
@config.shuffle!(examples)
|
||||
end
|
||||
end
|
||||
|
||||
# Runs a single example and returns the result.
|
||||
# The formatter is given the example and result information.
|
||||
private def run_example(example)
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
module Spectator
|
||||
# Encapsulates the tests to run and additional properties about them.
|
||||
# Use `#each` to enumerate over all tests in the suite.
|
||||
class TestSuite
|
||||
include Enumerable(Example)
|
||||
|
||||
# Creates the test suite.
|
||||
# The example *group* provided will be run.
|
||||
# The *filter* identifies which examples to run from the *group*.
|
||||
def initialize(@group : ExampleGroup, @filter : ExampleFilter)
|
||||
end
|
||||
|
||||
# Yields each example in the test suite.
|
||||
def each : Nil
|
||||
iterator.each do |example|
|
||||
yield example if @filter.includes?(example)
|
||||
end
|
||||
end
|
||||
|
||||
# Creates an iterator for the example group.
|
||||
private def iterator
|
||||
ExampleIterator.new(@group)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue