Add filter to TestSuite

This commit is contained in:
Michael Miller 2019-03-25 11:35:39 -06:00
parent 49c396714e
commit 2ff9505766
5 changed files with 32 additions and 18 deletions

View file

@ -98,7 +98,7 @@ module Spectator
# Builds the tests and runs the framework.
private def run
# Build the test suite and run it.
suite = ::Spectator::DSL::Builder.build
suite = ::Spectator::DSL::Builder.build(config.example_filter)
Runner.new(suite, config).run
rescue ex
# Catch all unhandled exceptions here.

View file

@ -103,9 +103,9 @@ module Spectator::DSL
# Builds the entire spec and returns it as a test suite.
# This should be called only once after the entire spec has been defined.
protected def build : TestSuite
protected def build(filter : ExampleFilter) : TestSuite
group = root_group.build(Internals::SampleValues.empty)
TestSuite.new(group)
TestSuite.new(group, filter)
end
end
end

View file

@ -6,13 +6,14 @@ module Spectator
# Creates the test suite.
# The example *group* provided will be run.
def initialize(@group : ExampleGroup)
# 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
yield example if @filter.includes?(example)
end
end