Add tests for adding/omitting the space in #to_s

This commit is contained in:
Michael Miller 2019-02-17 17:03:57 -07:00
parent fe083b0f74
commit 6cc3c5e20b
3 changed files with 131 additions and 4 deletions

View file

@ -1,5 +1,10 @@
# Example that always succeeds.
class PassingExample < Spectator::RunnableExample
# Creates the example.
def initialize(group, values, @symbolic = false)
super(group, values)
end
# Dummy description.
def what
"PASS"
@ -12,7 +17,7 @@ class PassingExample < Spectator::RunnableExample
# Dummy symbolic flag.
def symbolic?
false
@symbolic
end
# Dummy instance.

View file

@ -630,6 +630,76 @@ describe Spectator::NestedExampleGroup do
group.children = [] of Spectator::ExampleComponent
group.to_s.should contain(parent.to_s)
end
context "when #symbolic? is true" do
context "and the parent group is symbolic" do
it "omits the space" do
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(:"#foo", parent, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [parent.as(Spectator::ExampleComponent)]
parent.children = [group.as(Spectator::ExampleComponent)]
group.children = [] of Spectator::ExampleComponent
parent.symbolic?.should be_true
group.symbolic?.should be_true
group.to_s.should_not contain(' ')
end
end
context "and the parent group isn't symbolic" do
it "inserts a space" do
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(:"#foo", parent, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [parent.as(Spectator::ExampleComponent)]
parent.children = [group.as(Spectator::ExampleComponent)]
group.children = [] of Spectator::ExampleComponent
parent.symbolic?.should be_false
group.symbolic?.should be_true
group.to_s.should contain(' ')
end
end
end
context "when #symbolic? is false" do
context "and the parent group is symbolic" do
it "inserts a space" do
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
parent.symbolic?.should be_true
group.symbolic?.should be_false
group.to_s.should contain(' ')
end
end
context "and the parent group isn't symbolic" do
it "inserts a space" do
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
parent.symbolic?.should be_false
group.symbolic?.should be_false
group.to_s.should contain(' ')
end
end
end
context "when the parent group is root" do
it "omits the space" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("GROUP", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
group.children = [] of Spectator::ExampleComponent
group.to_s.should_not contain(' ')
end
end
end
describe "#children" do

View file

@ -1,8 +1,8 @@
require "./spec_helper"
def new_runnable_example(group : Spectator::ExampleGroup? = nil)
def new_runnable_example(group : Spectator::ExampleGroup? = nil, symbolic = false)
actual_group = group || Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
PassingExample.new(actual_group, Spectator::Internals::SampleValues.empty).tap do |example|
PassingExample.new(actual_group, Spectator::Internals::SampleValues.empty, symbolic).tap do |example|
actual_group.children = [example.as(Spectator::ExampleComponent)]
end
end
@ -1507,10 +1507,62 @@ describe Spectator::RunnableExample do
it "contains the group's #what" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("the parent", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("GROUP", 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.to_s)
end
context "when #symbolic? is true" do
context "and the group is symbolic" do
it "omits the space" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new(:Group, root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
example = new_runnable_example(group, true)
group.symbolic?.should be_true
example.symbolic?.should be_true
example.to_s.should_not contain(' ')
end
end
context "and the group isn't symbolic" do
it "inserts a space" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("GROUP", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
example = new_runnable_example(group, true)
group.symbolic?.should be_false
example.symbolic?.should be_true
example.to_s.should contain(' ')
end
end
end
context "when #symbolic? is false" do
context "and the group is symbolic" do
it "inserts a space" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new(:Group, root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
example = new_runnable_example(group, false)
group.symbolic?.should be_true
example.symbolic?.should be_false
example.to_s.should contain(' ')
end
end
context "and the group isn't symbolic" do
it "inserts a space" do
root = Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
group = Spectator::NestedExampleGroup.new("GROUP", root, Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty)
root.children = [group.as(Spectator::ExampleComponent)]
example = new_runnable_example(group, false)
group.symbolic?.should be_false
example.symbolic?.should be_false
example.to_s.should contain(' ')
end
end
end
end
end