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
|
builder.build
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_test_suite
|
def new_test_suite(group : Spectator::ExampleGroup? = nil)
|
||||||
example = PassingExample.create
|
filter = Spectator::NullExampleFilter.new
|
||||||
Spectator::TestSuite.new(example.group)
|
Spectator::TestSuite.new(group || PassingExample.create.group, filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Spectator::Runner do
|
describe Spectator::Runner do
|
||||||
|
@ -21,7 +21,7 @@ describe Spectator::Runner do
|
||||||
called << index
|
called << index
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config)
|
runner = Spectator::Runner.new(suite, spectator_test_config)
|
||||||
runner.run
|
runner.run
|
||||||
called.should eq([0, 1, 2, 3, 4])
|
called.should eq([0, 1, 2, 3, 4])
|
||||||
|
@ -34,7 +34,7 @@ describe Spectator::Runner do
|
||||||
called << index
|
called << index
|
||||||
raise "Failure" if index > 5
|
raise "Failure" if index > 5
|
||||||
end
|
end
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true))
|
runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true))
|
||||||
runner.run
|
runner.run
|
||||||
called.should eq([0, 1, 2, 3, 4, 5, 6])
|
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|
|
group = SpyExample.create_group(10) do |index|
|
||||||
raise "Failure" if index > 5
|
raise "Failure" if index > 5
|
||||||
end
|
end
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy, true))
|
runner = Spectator::Runner.new(suite, spectator_test_config(spy, true))
|
||||||
runner.run
|
runner.run
|
||||||
report = spy.end_suite_calls.first
|
report = spy.end_suite_calls.first
|
||||||
|
@ -101,7 +101,7 @@ describe Spectator::Runner do
|
||||||
|
|
||||||
it "#start_example is called for each example" do
|
it "#start_example is called for each example" do
|
||||||
group = SpyExample.create_group(5) { |index| nil }
|
group = SpyExample.create_group(5) { |index| nil }
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
spy = SpyFormatter.new
|
spy = SpyFormatter.new
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||||
runner.run
|
runner.run
|
||||||
|
@ -110,7 +110,7 @@ describe Spectator::Runner do
|
||||||
|
|
||||||
it "passes the correct example to #start_example" do
|
it "passes the correct example to #start_example" do
|
||||||
group = SpyExample.create_group(5) { |index| nil }
|
group = SpyExample.create_group(5) { |index| nil }
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
spy = SpyFormatter.new
|
spy = SpyFormatter.new
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||||
runner.run
|
runner.run
|
||||||
|
@ -126,7 +126,7 @@ describe Spectator::Runner do
|
||||||
|
|
||||||
it "calls #end_example for each example" do
|
it "calls #end_example for each example" do
|
||||||
group = SpyExample.create_group(5) { |index| nil }
|
group = SpyExample.create_group(5) { |index| nil }
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
spy = SpyFormatter.new
|
spy = SpyFormatter.new
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||||
runner.run
|
runner.run
|
||||||
|
@ -142,7 +142,7 @@ describe Spectator::Runner do
|
||||||
FailingExample.new(group, Spectator::Internals::SampleValues.empty)
|
FailingExample.new(group, Spectator::Internals::SampleValues.empty)
|
||||||
end.as(Spectator::ExampleComponent)
|
end.as(Spectator::ExampleComponent)
|
||||||
end
|
end
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
spy = SpyFormatter.new
|
spy = SpyFormatter.new
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||||
runner.run
|
runner.run
|
||||||
|
@ -160,7 +160,7 @@ describe Spectator::Runner do
|
||||||
FailingExample.new(group, Spectator::Internals::SampleValues.empty)
|
FailingExample.new(group, Spectator::Internals::SampleValues.empty)
|
||||||
end.as(Spectator::ExampleComponent)
|
end.as(Spectator::ExampleComponent)
|
||||||
end
|
end
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
spy = SpyFormatter.new
|
spy = SpyFormatter.new
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||||
runner.run
|
runner.run
|
||||||
|
@ -175,7 +175,7 @@ describe Spectator::Runner do
|
||||||
|
|
||||||
it "contains the expected time span" do
|
it "contains the expected time span" do
|
||||||
group = SpyExample.create_group(5) { |index| nil }
|
group = SpyExample.create_group(5) { |index| nil }
|
||||||
suite = Spectator::TestSuite.new(group)
|
suite = new_test_suite(group)
|
||||||
spy = SpyFormatter.new
|
spy = SpyFormatter.new
|
||||||
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
runner = Spectator::Runner.new(suite, spectator_test_config(spy))
|
||||||
max_time = Time.measure { runner.run }
|
max_time = Time.measure { runner.run }
|
||||||
|
|
|
@ -7,12 +7,25 @@ describe Spectator::TestSuite do
|
||||||
group.children = Array.new(5) do |index|
|
group.children = Array.new(5) do |index|
|
||||||
PassingExample.new(group, Spectator::Internals::SampleValues.empty).as(Spectator::ExampleComponent)
|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).as(Spectator::ExampleComponent)
|
||||||
end
|
end
|
||||||
test_suite = Spectator::TestSuite.new(group)
|
test_suite = Spectator::TestSuite.new(group, Spectator::NullExampleFilter.new)
|
||||||
examples = [] of Spectator::Example
|
examples = [] of Spectator::Example
|
||||||
test_suite.each do |example|
|
test_suite.each do |example|
|
||||||
examples << example
|
examples << example
|
||||||
end
|
end
|
||||||
examples.should eq(group.children)
|
examples.should eq(group.children)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,7 +98,7 @@ 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 suite and run it.
|
# 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
|
Runner.new(suite, config).run
|
||||||
rescue ex
|
rescue ex
|
||||||
# Catch all unhandled exceptions here.
|
# Catch all unhandled exceptions here.
|
||||||
|
|
|
@ -103,9 +103,9 @@ module Spectator::DSL
|
||||||
|
|
||||||
# Builds the entire spec and returns it as a test suite.
|
# Builds the entire spec and returns it as a test suite.
|
||||||
# This should be called only once after the entire spec has been defined.
|
# 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)
|
group = root_group.build(Internals::SampleValues.empty)
|
||||||
TestSuite.new(group)
|
TestSuite.new(group, filter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,13 +6,14 @@ module Spectator
|
||||||
|
|
||||||
# Creates the test suite.
|
# Creates the test suite.
|
||||||
# The example *group* provided will be run.
|
# 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
|
end
|
||||||
|
|
||||||
# Yields each example in the test suite.
|
# Yields each example in the test suite.
|
||||||
def each : Nil
|
def each : Nil
|
||||||
iterator.each do |example|
|
iterator.each do |example|
|
||||||
yield example
|
yield example if @filter.includes?(example)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue