From 6cc3c5e20bd9f0ccee90af5d5ba264bddb0d02e8 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 17 Feb 2019 17:03:57 -0700 Subject: [PATCH] Add tests for adding/omitting the space in #to_s --- spec/helpers/passing_example.cr | 7 +++- spec/nested_example_group_spec.cr | 70 +++++++++++++++++++++++++++++++ spec/runnable_example_spec.cr | 58 +++++++++++++++++++++++-- 3 files changed, 131 insertions(+), 4 deletions(-) diff --git a/spec/helpers/passing_example.cr b/spec/helpers/passing_example.cr index 80a2884..9537c61 100644 --- a/spec/helpers/passing_example.cr +++ b/spec/helpers/passing_example.cr @@ -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. diff --git a/spec/nested_example_group_spec.cr b/spec/nested_example_group_spec.cr index 0345328..63d53ca 100644 --- a/spec/nested_example_group_spec.cr +++ b/spec/nested_example_group_spec.cr @@ -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 diff --git a/spec/runnable_example_spec.cr b/spec/runnable_example_spec.cr index 8d28bcb..602dc38 100644 --- a/spec/runnable_example_spec.cr +++ b/spec/runnable_example_spec.cr @@ -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