mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add filter to TestSuite
This commit is contained in:
parent
49c396714e
commit
2ff9505766
5 changed files with 32 additions and 18 deletions
|
@ -8,9 +8,9 @@ def spectator_test_config(formatter : Spectator::Formatting::Formatter? = nil, f
|
|||
builder.build
|
||||
end
|
||||
|
||||
def new_test_suite
|
||||
example = PassingExample.create
|
||||
Spectator::TestSuite.new(example.group)
|
||||
def new_test_suite(group : Spectator::ExampleGroup? = nil)
|
||||
filter = Spectator::NullExampleFilter.new
|
||||
Spectator::TestSuite.new(group || PassingExample.create.group, filter)
|
||||
end
|
||||
|
||||
describe Spectator::Runner do
|
||||
|
@ -21,7 +21,7 @@ describe Spectator::Runner do
|
|||
called << index
|
||||
nil
|
||||
end
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config)
|
||||
runner.run
|
||||
called.should eq([0, 1, 2, 3, 4])
|
||||
|
@ -34,7 +34,7 @@ describe Spectator::Runner do
|
|||
called << index
|
||||
raise "Failure" if index > 5
|
||||
end
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true))
|
||||
runner.run
|
||||
called.should eq([0, 1, 2, 3, 4, 5, 6])
|
||||
|
@ -46,7 +46,7 @@ describe Spectator::Runner do
|
|||
group = SpyExample.create_group(10) do |index|
|
||||
raise "Failure" if index > 5
|
||||
end
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy, true))
|
||||
runner.run
|
||||
report = spy.end_suite_calls.first
|
||||
|
@ -101,7 +101,7 @@ describe Spectator::Runner do
|
|||
|
||||
it "#start_example is called for each example" do
|
||||
group = SpyExample.create_group(5) { |index| nil }
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
spy = SpyFormatter.new
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||
runner.run
|
||||
|
@ -110,7 +110,7 @@ describe Spectator::Runner do
|
|||
|
||||
it "passes the correct example to #start_example" do
|
||||
group = SpyExample.create_group(5) { |index| nil }
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
spy = SpyFormatter.new
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||
runner.run
|
||||
|
@ -126,7 +126,7 @@ describe Spectator::Runner do
|
|||
|
||||
it "calls #end_example for each example" do
|
||||
group = SpyExample.create_group(5) { |index| nil }
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
spy = SpyFormatter.new
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||
runner.run
|
||||
|
@ -142,7 +142,7 @@ describe Spectator::Runner do
|
|||
FailingExample.new(group, Spectator::Internals::SampleValues.empty)
|
||||
end.as(Spectator::ExampleComponent)
|
||||
end
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
spy = SpyFormatter.new
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||
runner.run
|
||||
|
@ -160,7 +160,7 @@ describe Spectator::Runner do
|
|||
FailingExample.new(group, Spectator::Internals::SampleValues.empty)
|
||||
end.as(Spectator::ExampleComponent)
|
||||
end
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
spy = SpyFormatter.new
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||
runner.run
|
||||
|
@ -175,7 +175,7 @@ describe Spectator::Runner do
|
|||
|
||||
it "contains the expected time span" do
|
||||
group = SpyExample.create_group(5) { |index| nil }
|
||||
suite = Spectator::TestSuite.new(group)
|
||||
suite = new_test_suite(group)
|
||||
spy = SpyFormatter.new
|
||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||
max_time = Time.measure { runner.run }
|
||||
|
|
|
@ -7,12 +7,25 @@ describe Spectator::TestSuite do
|
|||
group.children = Array.new(5) do |index|
|
||||
PassingExample.new(group, Spectator::Internals::SampleValues.empty).as(Spectator::ExampleComponent)
|
||||
end
|
||||
test_suite = Spectator::TestSuite.new(group)
|
||||
test_suite = Spectator::TestSuite.new(group, Spectator::NullExampleFilter.new)
|
||||
examples = [] of Spectator::Example
|
||||
test_suite.each do |example|
|
||||
examples << example
|
||||
end
|
||||
examples.should eq(group.children)
|
||||
end
|
||||
|
||||
it "skips examples not in the filter" do
|
||||
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
|
||||
group.children = Array.new(5) do |index|
|
||||
PassingExample.new(group, Spectator::Internals::SampleValues.empty).as(Spectator::ExampleComponent)
|
||||
end
|
||||
test_suite = Spectator::TestSuite.new(group, Spectator::CompositeExampleFilter.new([] of Spectator::ExampleFilter))
|
||||
examples = [] of Spectator::Example
|
||||
test_suite.each do |example|
|
||||
examples << example
|
||||
end
|
||||
examples.should be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue