Update existing specs to support conditions

This commit is contained in:
Michael Miller 2019-01-11 10:09:40 -07:00
parent 38202ff605
commit d9363fc8a7
8 changed files with 171 additions and 169 deletions

View file

@ -4,21 +4,21 @@ describe Spectator::DSL::ExampleFactory do
describe "#build" do
it "creates an example of the correct type" do
factory = Spectator::DSL::ExampleFactory.new(SpyExample)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
example = factory.build(group, Spectator::Internals::SampleValues.empty)
example.should be_a(SpyExample)
end
it "passes along the group" do
factory = Spectator::DSL::ExampleFactory.new(SpyExample)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
example = factory.build(group, Spectator::Internals::SampleValues.empty)
example.group.should eq(group)
end
it "passes along the sample values" do
factory = Spectator::DSL::ExampleFactory.new(SpyExample)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
values = Spectator::Internals::SampleValues.empty.add(:foo, "foo", 12345)
example = factory.build(group, values)
example.as(SpyExample).sample_values.should eq(values)

View file

@ -19,7 +19,7 @@ describe Spectator::ExampleIterator do
context "when empty" do
it "returns 'stop'" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = [] of Spectator::ExampleComponent
iterator = Spectator::ExampleIterator.new(group)
iterator.next.should be_a(Iterator::Stop)
@ -29,7 +29,7 @@ describe Spectator::ExampleIterator do
context "with one level of examples" do
it "iterates through all examples" do
examples = [] of Spectator::Example
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |_|
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
end
@ -39,7 +39,7 @@ describe Spectator::ExampleIterator do
end
it "returns 'stop' at the end" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |_|
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
end
@ -52,9 +52,9 @@ describe Spectator::ExampleIterator do
context "with empty sub-groups" do
context "one level deep" do
it "returns 'stop'" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end
@ -65,11 +65,11 @@ describe Spectator::ExampleIterator do
context "multiple levels deep" do
it "returns 'stop'" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(5) do |j|
Spectator::NestedExampleGroup.new(j.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_sub_group|
Spectator::NestedExampleGroup.new(j.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_sub_group|
sub_sub_group.children = [] of Spectator::ExampleComponent
end
end
@ -85,14 +85,14 @@ describe Spectator::ExampleIterator do
it "iterates through all examples" do
actual_examples = [] of Spectator::Example
expected_examples = [] of Spectator::Example
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
expected_examples << example
end
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(5) do |j|
PassingExample.new(sub_group, Spectator::Internals::SampleValues.empty).tap do |example|
expected_examples << example
@ -107,12 +107,12 @@ describe Spectator::ExampleIterator do
end
it "returns 'stop' at the end" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(5) do |j|
PassingExample.new(sub_group, Spectator::Internals::SampleValues.empty)
end
@ -131,13 +131,13 @@ describe Spectator::ExampleIterator do
it "iterates through all examples" do
actual_examples = [] of Spectator::Example
expected_examples = [] of Spectator::Example
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group1|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group1|
sub_group1.children = Array(Spectator::ExampleComponent).new(5) do |j|
Spectator::NestedExampleGroup.new(j.to_s, sub_group1, Spectator::ExampleHooks.empty).tap do |sub_group2|
Spectator::NestedExampleGroup.new(j.to_s, sub_group1, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group2|
sub_group2.children = Array(Spectator::ExampleComponent).new(5) do |k|
Spectator::NestedExampleGroup.new(k.to_s, sub_group2, Spectator::ExampleHooks.empty).tap do |sub_group3|
Spectator::NestedExampleGroup.new(k.to_s, sub_group2, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group3|
sub_group3.children = Array(Spectator::ExampleComponent).new(5) do |_|
PassingExample.new(sub_group3, Spectator::Internals::SampleValues.empty).tap do |example|
expected_examples << example
@ -155,13 +155,13 @@ describe Spectator::ExampleIterator do
end
it "returns 'stop' at the end" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group1|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group1|
sub_group1.children = Array(Spectator::ExampleComponent).new(5) do |j|
Spectator::NestedExampleGroup.new(j.to_s, sub_group1, Spectator::ExampleHooks.empty).tap do |sub_group2|
Spectator::NestedExampleGroup.new(j.to_s, sub_group1, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group2|
sub_group2.children = Array(Spectator::ExampleComponent).new(5) do |k|
Spectator::NestedExampleGroup.new(k.to_s, sub_group2, Spectator::ExampleHooks.empty).tap do |sub_group3|
Spectator::NestedExampleGroup.new(k.to_s, sub_group2, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group3|
sub_group3.children = Array(Spectator::ExampleComponent).new(5) do |_|
PassingExample.new(sub_group3, Spectator::Internals::SampleValues.empty)
end

View file

@ -18,7 +18,8 @@ class FailingExample < Spectator::RunnableExample
# Creates a failing example.
def self.create
hooks = Spectator::ExampleHooks.empty
group = Spectator::RootExampleGroup.new(hooks)
conditions = Spectator::ExampleConditions.empty
group = Spectator::RootExampleGroup.new(hooks, conditions)
values = Spectator::Internals::SampleValues.empty
new(group, values).tap do |example|
group.children = [example.as(Spectator::ExampleComponent)]

View file

@ -19,7 +19,8 @@ class PassingExample < Spectator::RunnableExample
# Creates a passing example.
def self.create
hooks = Spectator::ExampleHooks.empty
group = Spectator::RootExampleGroup.new(hooks)
conditions = Spectator::ExampleConditions.empty
group = Spectator::RootExampleGroup.new(hooks, conditions)
values = Spectator::Internals::SampleValues.empty
new(group, values).tap do |example|
group.children = [example.as(Spectator::ExampleComponent)]

View file

@ -34,8 +34,8 @@ class SpyExample < Spectator::RunnableExample
# Creates a spy example.
# The block passed to this method will be executed when the example runs.
def self.create(hooks = Spectator::ExampleHooks.empty, &block)
group = Spectator::RootExampleGroup.new(hooks)
def self.create(hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty, &block)
group = Spectator::RootExampleGroup.new(hooks, conditions)
values = Spectator::Internals::SampleValues.empty
new(group, values).tap do |example|
group.children = [example.as(Spectator::ExampleComponent)]

View file

@ -1,16 +1,16 @@
require "./spec_helper"
def new_nested_group(hooks = Spectator::ExampleHooks.empty, parent : Spectator::ExampleGroup? = nil)
parent ||= Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
Spectator::NestedExampleGroup.new("what", parent, hooks).tap do |group|
parent ||= Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
Spectator::NestedExampleGroup.new("what", parent, hooks, Spectator::ExampleConditions.empty).tap do |group|
parent.children = [group.as(Spectator::ExampleComponent)]
group.children = [] of Spectator::ExampleComponent
end
end
def nested_group_with_examples(example_count = 5)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
examples = [] of Spectator::Example
group.children = Array(Spectator::ExampleComponent).new(example_count) do
@ -22,12 +22,12 @@ def nested_group_with_examples(example_count = 5)
end
def nested_group_with_sub_groups(sub_group_count = 5, example_count = 5)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
examples = [] of Spectator::Example
group.children = Array(Spectator::ExampleComponent).new(sub_group_count) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(example_count) do |j|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
examples << example
@ -39,8 +39,8 @@ def nested_group_with_sub_groups(sub_group_count = 5, example_count = 5)
end
def complex_nested_group
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
examples = [] of Spectator::Example
group.children = Array(Spectator::ExampleComponent).new(10) do |i|
@ -49,14 +49,14 @@ def complex_nested_group
examples << example
end
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group1|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group1|
sub_group1.children = Array(Spectator::ExampleComponent).new(10) do |j|
if i % 2 == 0
PassingExample.new(sub_group1, Spectator::Internals::SampleValues.empty).tap do |example|
examples << example
end
else
Spectator::NestedExampleGroup.new(j.to_s, sub_group1, Spectator::ExampleHooks.empty).tap do |sub_group2|
Spectator::NestedExampleGroup.new(j.to_s, sub_group1, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group2|
sub_group2.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(sub_group2, Spectator::Internals::SampleValues.empty).tap do |example|
examples << example
@ -75,16 +75,16 @@ describe Spectator::NestedExampleGroup do
describe "#what" do
it "is the expected value" do
what = "foobar"
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new(what, root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new(what, root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.what.should eq(what)
end
end
describe "#parent" do
it "is the expected value" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.parent.should eq(root)
end
end
@ -150,7 +150,7 @@ describe Spectator::NestedExampleGroup do
it "runs the parent before_all hooks" do
called = false
hooks = new_hooks(before_all: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(parent: root)
group.run_before_hooks
called.should be_true
@ -159,7 +159,7 @@ describe Spectator::NestedExampleGroup do
it "runs the parent before_each hooks" do
called = false
hooks = new_hooks(before_each: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(parent: root)
group.run_before_hooks
called.should be_true
@ -169,7 +169,7 @@ describe Spectator::NestedExampleGroup do
calls = [] of Symbol
root_hooks = new_hooks(before_all: ->{ calls << :a; nil })
group_hooks = new_hooks(before_all: ->{ calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(group_hooks, root)
group.run_before_hooks
calls.should eq(%i[a b])
@ -179,7 +179,7 @@ describe Spectator::NestedExampleGroup do
calls = [] of Symbol
root_hooks = new_hooks(before_each: ->{ calls << :a; nil })
group_hooks = new_hooks(before_each: ->{ calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(group_hooks, root)
group.run_before_hooks
calls.should eq(%i[a b])
@ -246,7 +246,7 @@ describe Spectator::NestedExampleGroup do
it "runs the parent after_all hooks" do
called = false
hooks = new_hooks(after_all: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(parent: root)
group.run_after_hooks
called.should be_true
@ -255,7 +255,7 @@ describe Spectator::NestedExampleGroup do
it "runs the parent after_each hooks" do
called = false
hooks = new_hooks(after_each: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(parent: root)
group.run_after_hooks
called.should be_true
@ -265,7 +265,7 @@ describe Spectator::NestedExampleGroup do
calls = [] of Symbol
root_hooks = new_hooks(after_all: ->{ calls << :a; nil })
group_hooks = new_hooks(after_all: ->{ calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(group_hooks, root)
group.run_after_hooks
calls.should eq(%i[b a])
@ -275,7 +275,7 @@ describe Spectator::NestedExampleGroup do
calls = [] of Symbol
root_hooks = new_hooks(after_each: ->{ calls << :a; nil })
group_hooks = new_hooks(after_each: ->{ calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(group_hooks, root)
group.run_after_hooks
calls.should eq(%i[b a])
@ -301,8 +301,8 @@ describe Spectator::NestedExampleGroup do
it "doesn't run the after_all hooks" do
called = false
hooks = new_hooks(after_all: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, hooks)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
@ -314,8 +314,8 @@ describe Spectator::NestedExampleGroup do
it "runs the after_each hooks" do
called = false
hooks = new_hooks(after_each: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, hooks)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
@ -327,8 +327,8 @@ describe Spectator::NestedExampleGroup do
it "doesn't run the parent after_all hooks" do
called = false
hooks = new_hooks(after_all: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
@ -340,8 +340,8 @@ describe Spectator::NestedExampleGroup do
it "runs the parent after_each hooks" do
called = false
hooks = new_hooks(after_each: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
@ -356,8 +356,8 @@ describe Spectator::NestedExampleGroup do
called = false
examples = [] of Spectator::Example
hooks = new_hooks(after_all: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, hooks)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
@ -375,8 +375,8 @@ describe Spectator::NestedExampleGroup do
called = false
examples = [] of Spectator::Example
hooks = new_hooks(after_each: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, hooks)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
@ -394,8 +394,8 @@ describe Spectator::NestedExampleGroup do
called = false
examples = [] of Spectator::Example
hooks = new_hooks(after_all: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
@ -413,8 +413,8 @@ describe Spectator::NestedExampleGroup do
called = false
examples = [] of Spectator::Example
hooks = new_hooks(after_each: ->{ called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
@ -475,7 +475,7 @@ describe Spectator::NestedExampleGroup do
it "wraps the parent hooks" do
called = false
hooks = new_hooks(around_each: ->(proc : ->) { called = true; proc.call })
root = Spectator::RootExampleGroup.new(hooks)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
wrapper = new_nested_group(parent: root).wrap_around_each_hooks { }
wrapper.call
called.should be_true
@ -485,7 +485,7 @@ describe Spectator::NestedExampleGroup do
calls = [] of Symbol
root_hooks = new_hooks(around_each: ->(proc : ->) { calls << :a; proc.call })
group_hooks = new_hooks(around_each: ->(proc : ->) { calls << :b; proc.call })
root = Spectator::RootExampleGroup.new(root_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = new_nested_group(group_hooks, root)
wrapper = group.wrap_around_each_hooks { }
wrapper.call
@ -500,9 +500,9 @@ describe Spectator::NestedExampleGroup do
end
it "contains the parent's #to_s" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
parent = Spectator::NestedExampleGroup.new("PARENT", root, Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("GROUP", parent, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
parent = Spectator::NestedExampleGroup.new("PARENT", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("GROUP", parent, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [parent.as(Spectator::ExampleComponent)]
parent.children = [group.as(Spectator::ExampleComponent)]
group.children = [] of Spectator::ExampleComponent
@ -512,15 +512,15 @@ describe Spectator::NestedExampleGroup do
describe "#children" do
it "raises an error when not set" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
expect_raises(Exception) { group.children }
end
it "returns the expected set" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
@ -532,8 +532,8 @@ describe Spectator::NestedExampleGroup do
describe "#children=" do
it "raises an error trying to reset" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
@ -545,14 +545,14 @@ describe Spectator::NestedExampleGroup do
describe "#each" do
it "yields each child" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end
@ -561,14 +561,14 @@ describe Spectator::NestedExampleGroup do
end
it "doesn't yield children of children" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(sub_group, Spectator::Internals::SampleValues.empty)
end
@ -581,14 +581,14 @@ describe Spectator::NestedExampleGroup do
describe "#each : Iterator" do
it "iterates over each child" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end
@ -597,14 +597,14 @@ describe Spectator::NestedExampleGroup do
end
it "doesn't iterate over children of children" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(sub_group, Spectator::Internals::SampleValues.empty)
end
@ -624,11 +624,11 @@ describe Spectator::NestedExampleGroup do
context "with empty sub-groups" do
it "is zero" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty)
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
end
group.example_count.should eq(0)
end
@ -831,11 +831,11 @@ describe Spectator::NestedExampleGroup do
context "with only sub-groups and no examples" do
it "raises an index error" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end
@ -881,11 +881,11 @@ describe Spectator::NestedExampleGroup do
context "with a sub-group" do
context "with no children" do
it "is true" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end

View file

@ -1,13 +1,13 @@
require "./spec_helper"
def new_root_group(hooks = Spectator::ExampleHooks.empty)
Spectator::RootExampleGroup.new(hooks).tap do |group|
def new_root_group(hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty)
Spectator::RootExampleGroup.new(hooks, conditions).tap do |group|
group.children = [] of Spectator::ExampleComponent
end
end
def root_group_with_examples(example_count = 5)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
examples = [] of Spectator::Example
group.children = Array(Spectator::ExampleComponent).new(example_count) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
@ -18,10 +18,10 @@ def root_group_with_examples(example_count = 5)
end
def root_group_with_sub_groups(sub_group_count = 5, example_count = 5)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
examples = [] of Spectator::Example
group.children = Array(Spectator::ExampleComponent).new(sub_group_count) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(example_count) do |j|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
examples << example
@ -33,7 +33,7 @@ def root_group_with_sub_groups(sub_group_count = 5, example_count = 5)
end
def complex_root_group
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
examples = [] of Spectator::Example
group.children = Array(Spectator::ExampleComponent).new(10) do |i|
if i % 2 == 0
@ -41,14 +41,14 @@ def complex_root_group
examples << example
end
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group1|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group1|
sub_group1.children = Array(Spectator::ExampleComponent).new(10) do |j|
if i % 2 == 0
PassingExample.new(sub_group1, Spectator::Internals::SampleValues.empty).tap do |example|
examples << example
end
else
Spectator::NestedExampleGroup.new(j.to_s, sub_group1, Spectator::ExampleHooks.empty).tap do |sub_group2|
Spectator::NestedExampleGroup.new(j.to_s, sub_group1, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group2|
sub_group2.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(sub_group2, Spectator::Internals::SampleValues.empty).tap do |example|
examples << example
@ -220,7 +220,7 @@ describe Spectator::RootExampleGroup do
it "doesn't run the after_all hooks" do
called = false
hooks = new_hooks(after_all: ->{ called = true; nil })
group = Spectator::RootExampleGroup.new(hooks)
group = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
end
@ -231,7 +231,7 @@ describe Spectator::RootExampleGroup do
it "runs the after_each hooks" do
called = false
hooks = new_hooks(after_each: ->{ called = true; nil })
group = Spectator::RootExampleGroup.new(hooks)
group = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
end
@ -245,7 +245,7 @@ describe Spectator::RootExampleGroup do
called = false
examples = [] of Spectator::Example
hooks = new_hooks(after_all: ->{ called = true; nil })
group = Spectator::RootExampleGroup.new(hooks)
group = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
examples << example
@ -262,7 +262,7 @@ describe Spectator::RootExampleGroup do
called = false
examples = [] of Spectator::Example
hooks = new_hooks(after_each: ->{ called = true; nil })
group = Spectator::RootExampleGroup.new(hooks)
group = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
examples << example
@ -328,12 +328,12 @@ describe Spectator::RootExampleGroup do
describe "#children" do
it "raises an error when not set" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
expect_raises(Exception) { group.children }
end
it "returns the expected set" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
end
@ -344,7 +344,7 @@ describe Spectator::RootExampleGroup do
describe "#children=" do
it "raises an error trying to reset" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
end
@ -355,12 +355,12 @@ describe Spectator::RootExampleGroup do
describe "#each" do
it "yields each child" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end
@ -369,12 +369,12 @@ describe Spectator::RootExampleGroup do
end
it "doesn't yield children of children" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(sub_group, Spectator::Internals::SampleValues.empty)
end
@ -387,12 +387,12 @@ describe Spectator::RootExampleGroup do
describe "#each : Iterator" do
it "iterates over each child" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end
@ -401,12 +401,12 @@ describe Spectator::RootExampleGroup do
end
it "doesn't iterate over children of children" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
if i % 2 == 0
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
else
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = Array(Spectator::ExampleComponent).new(5) do
PassingExample.new(sub_group, Spectator::Internals::SampleValues.empty)
end
@ -426,9 +426,9 @@ describe Spectator::RootExampleGroup do
context "with empty sub-groups" do
it "is zero" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty)
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
end
group.example_count.should eq(0)
end
@ -631,9 +631,9 @@ describe Spectator::RootExampleGroup do
context "with only sub-groups and no examples" do
it "raises an index error" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end
@ -679,9 +679,9 @@ describe Spectator::RootExampleGroup do
context "with a sub-group" do
context "with no children" do
it "is true" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty).tap do |sub_group|
Spectator::NestedExampleGroup.new(i.to_s, group, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |sub_group|
sub_group.children = [] of Spectator::ExampleComponent
end
end

View file

@ -1,19 +1,19 @@
require "./spec_helper"
def new_runnable_example(group : Spectator::ExampleGroup? = nil)
actual_group = group || Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
actual_group = group || Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
PassingExample.new(actual_group, Spectator::Internals::SampleValues.empty).tap do |example|
actual_group.children = [example.as(Spectator::ExampleComponent)]
end
end
def run_example(example_type : Spectator::Example.class, hooks : Spectator::ExampleHooks? = nil)
group = Spectator::RootExampleGroup.new(hooks || Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(hooks || Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
run_example(example_type, group)
end
def run_example(example_type : Spectator::Example.class, group : Spectator::ExampleGroup? = nil)
actual_group = group || Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
actual_group = group || Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
example = example_type.new(actual_group, Spectator::Internals::SampleValues.empty)
actual_group.children = [example.as(Spectator::ExampleComponent)]
Spectator::Internals::Harness.run(example)
@ -65,8 +65,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks({{hook_type.id}}: -> { called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(PassingExample, group)
called.should be_true
@ -76,8 +76,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks({{hook_type.id}}: -> { calls << :a; nil })
group_hooks = new_hooks({{hook_type.id}}: -> { calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(PassingExample, group)
calls.should eq(\%i[a b])
@ -119,8 +119,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks({{hook_type.id}}: -> { called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(PassingExample, group)
called.should be_true
@ -130,8 +130,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks({{hook_type.id}}: -> { calls << :a; nil })
group_hooks = new_hooks({{hook_type.id}}: -> { calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(PassingExample, group)
calls.should eq(\%i[b a])
@ -172,8 +172,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks(around_each: ->(proc : ->) { called = true; proc.call })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(PassingExample, group)
called.should be_true
@ -183,8 +183,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks(around_each: ->(proc : ->) { calls << :a; proc.call })
group_hooks = new_hooks(around_each: ->(proc : ->) { calls << :b; proc.call })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(PassingExample, group)
calls.should eq(%i[a b])
@ -231,8 +231,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks({{hook_type.id}}: -> { called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(FailingExample, group)
called.should be_true
@ -242,8 +242,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks({{hook_type.id}}: -> { calls << :a; nil })
group_hooks = new_hooks({{hook_type.id}}: -> { calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(FailingExample, group)
calls.should eq(\%i[a b])
@ -285,8 +285,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks({{hook_type.id}}: -> { called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(FailingExample, group)
called.should be_true
@ -296,8 +296,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks({{hook_type.id}}: -> { calls << :a; nil })
group_hooks = new_hooks({{hook_type.id}}: -> { calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(FailingExample, group)
calls.should eq(\%i[b a])
@ -338,8 +338,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks(around_each: ->(proc : ->) { called = true; proc.call })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(FailingExample, group)
called.should be_true
@ -349,8 +349,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks(around_each: ->(proc : ->) { calls << :a; proc.call })
group_hooks = new_hooks(around_each: ->(proc : ->) { calls << :b; proc.call })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(FailingExample, group)
calls.should eq(%i[a b])
@ -397,8 +397,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks({{hook_type.id}}: -> { called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(ErroredExample, group)
called.should be_true
@ -408,8 +408,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks({{hook_type.id}}: -> { calls << :a; nil })
group_hooks = new_hooks({{hook_type.id}}: -> { calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(ErroredExample, group)
calls.should eq(\%i[a b])
@ -451,8 +451,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks({{hook_type.id}}: -> { called = true; nil })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(ErroredExample, group)
called.should be_true
@ -462,8 +462,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks({{hook_type.id}}: -> { calls << :a; nil })
group_hooks = new_hooks({{hook_type.id}}: -> { calls << :b; nil })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(ErroredExample, group)
calls.should eq(\%i[b a])
@ -504,8 +504,8 @@ describe Spectator::RunnableExample do
it "runs parent group hooks" do
called = false
hooks = new_hooks(around_each: ->(proc : ->) { called = true; proc.call })
root = Spectator::RootExampleGroup.new(hooks)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(ErroredExample, group)
called.should be_true
@ -515,8 +515,8 @@ describe Spectator::RunnableExample do
calls = [] of Symbol
root_hooks = new_hooks(around_each: ->(proc : ->) { calls << :a; proc.call })
group_hooks = new_hooks(around_each: ->(proc : ->) { calls << :b; proc.call })
root = Spectator::RootExampleGroup.new(root_hooks)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks)
root = Spectator::RootExampleGroup.new(root_hooks, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("what", root, group_hooks, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
run_example(ErroredExample, group)
calls.should eq(%i[a b])
@ -780,7 +780,7 @@ describe Spectator::RunnableExample do
describe "#group" do
it "is the expected value" do
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
example = new_runnable_example(group)
example.group.should eq(group)
end
@ -806,8 +806,8 @@ describe Spectator::RunnableExample do
end
it "contains the group's #what" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty)
group = Spectator::NestedExampleGroup.new("the parent", root, Spectator::ExampleHooks.empty)
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("the parent", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
example = new_runnable_example(group)
example.to_s.should contain(group.what)