Update specs to handle and test symbolic components

This commit is contained in:
Michael Miller 2019-02-17 16:39:23 -07:00
parent f6a4e6f558
commit fe083b0f74
8 changed files with 57 additions and 13 deletions

View file

@ -10,6 +10,11 @@ class ErroredExample < Spectator::RunnableExample
::Spectator::Source.new(__FILE__, __LINE__)
end
# Dummy symbolic flag.
def symbolic?
false
end
# Dummy instance.
def instance
nil

View file

@ -10,6 +10,11 @@ class FailingExample < Spectator::RunnableExample
::Spectator::Source.new(__FILE__, __LINE__)
end
# Dummy symbolic flag.
def symbolic?
false
end
# Dummy instance.
def instance
nil

View file

@ -10,6 +10,11 @@ class PassingExample < Spectator::RunnableExample
::Spectator::Source.new(__FILE__, __LINE__)
end
# Dummy symbolic flag.
def symbolic?
false
end
# Dummy instance.
def instance
nil

View file

@ -11,6 +11,11 @@ class SpyExample < Spectator::RunnableExample
::Spectator::Source.new(__FILE__, __LINE__)
end
# Dummy symbolic flag.
def symbolic?
false
end
# Dummy instance.
def instance
nil

View file

@ -1,8 +1,8 @@
require "./spec_helper"
def new_nested_group(hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty, parent : Spectator::ExampleGroup? = nil)
def new_nested_group(what : Symbol | String = "what", hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty, parent : Spectator::ExampleGroup? = nil)
parent ||= Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
Spectator::NestedExampleGroup.new("what", parent, hooks, conditions).tap do |group|
Spectator::NestedExampleGroup.new(what, parent, hooks, conditions).tap do |group|
parent.children = [group.as(Spectator::ExampleComponent)]
group.children = [] of Spectator::ExampleComponent
end
@ -93,7 +93,7 @@ describe Spectator::NestedExampleGroup do
it "runs a single before_all hook" do
called = false
hooks = new_hooks(before_all: ->{ called = true; nil })
group = new_nested_group(hooks)
group = new_nested_group(hooks: hooks)
group.run_before_hooks
called.should be_true
end
@ -101,7 +101,7 @@ describe Spectator::NestedExampleGroup do
it "runs a single before_each hook" do
called = false
hooks = new_hooks(before_each: ->{ called = true; nil })
group = new_nested_group(hooks)
group = new_nested_group(hooks: hooks)
group.run_before_hooks
called.should be_true
end
@ -113,7 +113,7 @@ describe Spectator::NestedExampleGroup do
->{ call_count += 2; nil },
->{ call_count += 3; nil },
])
group = new_nested_group(hooks)
group = new_nested_group(hooks: hooks)
group.run_before_hooks
call_count.should eq(6)
end
@ -125,7 +125,7 @@ describe Spectator::NestedExampleGroup do
->{ call_count += 2; nil },
->{ call_count += 3; nil },
])
group = new_nested_group(hooks)
group = new_nested_group(hooks: hooks)
group.run_before_hooks
call_count.should eq(6)
end
@ -142,7 +142,7 @@ describe Spectator::NestedExampleGroup do
->{ calls << :e; nil },
->{ calls << :f; nil },
])
group = new_nested_group(hooks)
group = new_nested_group(hooks: hooks)
group.run_before_hooks
calls.should eq(%i[a b c d e f])
end
@ -443,7 +443,7 @@ describe Spectator::NestedExampleGroup do
it "wraps a proc" do
called = false
hooks = new_hooks(around_each: ->(proc : ->) { called = true; proc.call })
wrapper = new_nested_group(hooks).wrap_around_each_hooks { }
wrapper = new_nested_group(hooks: hooks).wrap_around_each_hooks { }
wrapper.call
called.should be_true
end
@ -455,7 +455,7 @@ describe Spectator::NestedExampleGroup do
->(proc : ->) { call_count += 2; proc.call },
->(proc : ->) { call_count += 3; proc.call },
])
wrapper = new_nested_group(hooks).wrap_around_each_hooks { }
wrapper = new_nested_group(hooks: hooks).wrap_around_each_hooks { }
wrapper.call
call_count.should eq(6)
end
@ -467,7 +467,7 @@ describe Spectator::NestedExampleGroup do
->(proc : ->) { calls << :b; proc.call },
->(proc : ->) { calls << :c; proc.call },
])
wrapper = new_nested_group(hooks).wrap_around_each_hooks { }
wrapper = new_nested_group(hooks: hooks).wrap_around_each_hooks { }
wrapper.call
calls.should eq(%i[a b c])
end
@ -618,7 +618,7 @@ describe Spectator::NestedExampleGroup do
describe "#to_s" do
it "contains #what" do
group = new_nested_group
group.to_s.should contain(group.what)
group.to_s.should contain(group.what.to_s)
end
it "contains the parent's #to_s" do
@ -1043,4 +1043,18 @@ describe Spectator::NestedExampleGroup do
end
end
end
describe "#symbolic?" do
context "when 'what' is a Symbol" do
it "is true" do
new_nested_group(:What).symbolic?.should be_true
end
end
context "when 'what' is a String" do
it "is false" do
new_nested_group("what").symbolic?.should be_false
end
end
end
end

View file

@ -9,6 +9,10 @@ class ConcretePendingExample < Spectator::PendingExample
::Spectator::Source.new(__FILE__, __LINE__)
end
def symbolic?
false
end
def instance
nil
end
@ -112,7 +116,7 @@ describe Spectator::PendingExample do
it "contains the group's #what" do
group = new_nested_group
example = new_pending_example(group)
example.to_s.should contain(group.what)
example.to_s.should contain(group.what.to_s)
end
end
end

View file

@ -801,4 +801,10 @@ describe Spectator::RootExampleGroup do
end
end
end
describe "#symbolic?" do
it "is true" do
new_root_group.symbolic?.should be_true
end
end
end

View file

@ -1510,7 +1510,7 @@ describe Spectator::RunnableExample do
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)
example.to_s.should contain(group.what.to_s)
end
end
end