2020-10-17 23:40:38 +00:00
|
|
|
require "./config"
|
2020-09-27 15:10:27 +00:00
|
|
|
require "./example_group"
|
2021-07-05 17:49:16 +00:00
|
|
|
require "./runner"
|
2020-09-13 00:37:14 +00:00
|
|
|
|
|
|
|
module Spectator
|
2021-05-09 05:38:13 +00:00
|
|
|
# Contains examples to be tested and configuration for running them.
|
2020-09-13 00:37:14 +00:00
|
|
|
class Spec
|
2021-05-09 05:38:13 +00:00
|
|
|
# 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.
|
2020-10-17 23:40:38 +00:00
|
|
|
def initialize(@root : ExampleGroup, @config : Config)
|
2020-10-17 17:23:51 +00:00
|
|
|
end
|
2020-09-27 15:10:27 +00:00
|
|
|
|
2021-05-09 05:38:13 +00:00
|
|
|
# Runs all selected examples and returns the results.
|
2021-05-17 02:23:16 +00:00
|
|
|
# True will be returned if the spec ran successfully,
|
|
|
|
# or false if there was at least one failure.
|
|
|
|
def run : Bool
|
2021-05-19 00:50:43 +00:00
|
|
|
random_seed = (@config.random_seed if @config.run_flags.randomize?)
|
|
|
|
runner = Runner.new(examples, @config.formatter, @config.run_flags, random_seed)
|
2021-05-16 18:22:00 +00:00
|
|
|
runner.run
|
2021-05-09 05:38:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Selects and shuffles the examples that should run.
|
|
|
|
private def examples
|
|
|
|
iterator = @config.iterator(@root)
|
2021-08-17 02:27:27 +00:00
|
|
|
@config.shuffle!(iterator.to_a)
|
2020-10-17 23:40:38 +00:00
|
|
|
end
|
2020-09-13 00:37:14 +00:00
|
|
|
end
|
|
|
|
end
|