From 6e3ec79a14c5aad4f197f100634d52c581ecdf09 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 12 Sep 2020 15:58:07 -0600 Subject: [PATCH] Remove SpecBuilder types --- src/spectator/spec_builder/example_builder.cr | 19 ----- .../spec_builder/example_group_builder.cr | 74 ------------------- .../spec_builder/example_group_stack.cr | 28 ------- .../nested_example_group_builder.cr | 18 ----- .../spec_builder/pending_example_builder.cr | 10 --- .../root_example_group_builder.cr | 15 ---- .../spec_builder/runnable_example_builder.cr | 10 --- .../sample_example_group_builder.cr | 30 -------- 8 files changed, 204 deletions(-) delete mode 100644 src/spectator/spec_builder/example_builder.cr delete mode 100644 src/spectator/spec_builder/example_group_builder.cr delete mode 100644 src/spectator/spec_builder/example_group_stack.cr delete mode 100644 src/spectator/spec_builder/nested_example_group_builder.cr delete mode 100644 src/spectator/spec_builder/pending_example_builder.cr delete mode 100644 src/spectator/spec_builder/root_example_group_builder.cr delete mode 100644 src/spectator/spec_builder/runnable_example_builder.cr delete mode 100644 src/spectator/spec_builder/sample_example_group_builder.cr diff --git a/src/spectator/spec_builder/example_builder.cr b/src/spectator/spec_builder/example_builder.cr deleted file mode 100644 index 378c024..0000000 --- a/src/spectator/spec_builder/example_builder.cr +++ /dev/null @@ -1,19 +0,0 @@ -require "../../spectator_test" -require "../test_values" -require "../test_wrapper" - -module Spectator::SpecBuilder - abstract class ExampleBuilder - alias FactoryMethod = TestValues -> ::SpectatorTest - - def initialize(@description : String?, @source : Source, @builder : FactoryMethod, @runner : TestMethod) - end - - abstract def build(group) : ExampleComponent - - private def build_test_wrapper(group) - test = @builder.call(group.context.values) - TestWrapper.new(@description, @source, test, @runner) - end - end -end diff --git a/src/spectator/spec_builder/example_group_builder.cr b/src/spectator/spec_builder/example_group_builder.cr deleted file mode 100644 index 950f99d..0000000 --- a/src/spectator/spec_builder/example_group_builder.cr +++ /dev/null @@ -1,74 +0,0 @@ -require "../test_context" -require "./example_builder" - -module Spectator::SpecBuilder - abstract class ExampleGroupBuilder - alias Child = NestedExampleGroupBuilder | ExampleBuilder - - private getter children = Deque(Child).new - - @before_each_hooks = Deque(TestMetaMethod).new - @after_each_hooks = Deque(TestMetaMethod).new - @before_all_hooks = Deque(->).new - @after_all_hooks = Deque(->).new - @around_each_hooks = Deque(::SpectatorTest, Proc(Nil) ->).new - @pre_conditions = Deque(TestMetaMethod).new - @post_conditions = Deque(TestMetaMethod).new - @default_stubs = {} of String => Deque(Mocks::MethodStub) - - def add_child(child : Child) - @children << child - end - - def add_before_each_hook(hook : TestMetaMethod) - @before_each_hooks << hook - end - - def add_after_each_hook(hook : TestMetaMethod) - @after_each_hooks << hook - end - - def add_before_all_hook(hook : ->) - @before_all_hooks << hook - end - - def add_after_all_hook(hook : ->) - @after_all_hooks << hook - end - - def add_around_each_hook(hook : ::SpectatorTest, Proc(Nil) ->) - @around_each_hooks << hook - end - - def add_pre_condition(hook : TestMetaMethod) - @pre_conditions << hook - end - - def add_post_condition(hook : TestMetaMethod) - @post_conditions << hook - end - - def add_default_stub(type : T.class, stub : Mocks::MethodStub) forall T - key = type.name - @default_stubs[key] = Deque(Mocks::MethodStub).new unless @default_stubs.has_key?(key) - @default_stubs[key].unshift(stub) - end - - private def build_hooks - ExampleHooks.new( - @before_all_hooks.to_a, - @before_each_hooks.to_a, - @after_all_hooks.to_a, - @after_each_hooks.to_a, - @around_each_hooks.to_a - ) - end - - private def build_conditions - ExampleConditions.new( - @pre_conditions.to_a, - @post_conditions.to_a - ) - end - end -end diff --git a/src/spectator/spec_builder/example_group_stack.cr b/src/spectator/spec_builder/example_group_stack.cr deleted file mode 100644 index 50385bb..0000000 --- a/src/spectator/spec_builder/example_group_stack.cr +++ /dev/null @@ -1,28 +0,0 @@ -require "./root_example_group_builder" -require "./nested_example_group_builder" - -module Spectator::SpecBuilder - struct ExampleGroupStack - getter root - - def initialize - @root = RootExampleGroupBuilder.new - @stack = Deque(ExampleGroupBuilder).new(1, @root) - end - - def current - @stack.last - end - - def push(group : NestedExampleGroupBuilder) - current.add_child(group) - @stack.push(group) - end - - def pop - raise "Attempted to pop root example group from stack" if current == root - - @stack.pop - end - end -end diff --git a/src/spectator/spec_builder/nested_example_group_builder.cr b/src/spectator/spec_builder/nested_example_group_builder.cr deleted file mode 100644 index 6d7bb77..0000000 --- a/src/spectator/spec_builder/nested_example_group_builder.cr +++ /dev/null @@ -1,18 +0,0 @@ -require "../test_context" -require "./example_group_builder" - -module Spectator::SpecBuilder - class NestedExampleGroupBuilder < ExampleGroupBuilder - def initialize(@description : String | Symbol, @source : Source) - end - - def build(parent_group) - context = TestContext.new(parent_group.context, build_hooks, build_conditions, parent_group.context.values, @default_stubs) - NestedExampleGroup.new(@description, @source, parent_group, context).tap do |group| - group.children = children.map do |child| - child.build(group).as(ExampleComponent) - end - end - end - end -end diff --git a/src/spectator/spec_builder/pending_example_builder.cr b/src/spectator/spec_builder/pending_example_builder.cr deleted file mode 100644 index 731b9ab..0000000 --- a/src/spectator/spec_builder/pending_example_builder.cr +++ /dev/null @@ -1,10 +0,0 @@ -require "./example_builder" - -module Spectator::SpecBuilder - class PendingExampleBuilder < ExampleBuilder - def build(group) : ExampleComponent - wrapper = build_test_wrapper(group) - PendingExample.new(group, wrapper).as(ExampleComponent) - end - end -end diff --git a/src/spectator/spec_builder/root_example_group_builder.cr b/src/spectator/spec_builder/root_example_group_builder.cr deleted file mode 100644 index 3dbbcf7..0000000 --- a/src/spectator/spec_builder/root_example_group_builder.cr +++ /dev/null @@ -1,15 +0,0 @@ -require "../test_values" -require "./example_group_builder" - -module Spectator::SpecBuilder - class RootExampleGroupBuilder < ExampleGroupBuilder - def build - context = TestContext.new(nil, build_hooks, build_conditions, TestValues.empty, {} of String => Deque(Mocks::MethodStub)) - RootExampleGroup.new(context).tap do |group| - group.children = children.map do |child| - child.build(group).as(ExampleComponent) - end - end - end - end -end diff --git a/src/spectator/spec_builder/runnable_example_builder.cr b/src/spectator/spec_builder/runnable_example_builder.cr deleted file mode 100644 index 8c22a15..0000000 --- a/src/spectator/spec_builder/runnable_example_builder.cr +++ /dev/null @@ -1,10 +0,0 @@ -require "./example_builder" - -module Spectator::SpecBuilder - class RunnableExampleBuilder < ExampleBuilder - def build(group) : ExampleComponent - wrapper = build_test_wrapper(group) - RunnableExample.new(group, wrapper).as(ExampleComponent) - end - end -end diff --git a/src/spectator/spec_builder/sample_example_group_builder.cr b/src/spectator/spec_builder/sample_example_group_builder.cr deleted file mode 100644 index 955ac7a..0000000 --- a/src/spectator/spec_builder/sample_example_group_builder.cr +++ /dev/null @@ -1,30 +0,0 @@ -require "./nested_example_group_builder" - -module Spectator::SpecBuilder - class SampleExampleGroupBuilder(T) < NestedExampleGroupBuilder - def initialize(description : String | Symbol, source : Source, @id : Symbol, @label : String, @collection_builder : TestValues -> Array(T)) - super(description, source) - end - - def build(parent_group) - values = parent_group.context.values - collection = @collection_builder.call(values) - context = TestContext.new(parent_group.context, build_hooks, build_conditions, values, @default_stubs) - NestedExampleGroup.new(@description, @source, parent_group, context).tap do |group| - group.children = collection.map do |element| - build_sub_group(group, element).as(ExampleComponent) - end - end - end - - private def build_sub_group(parent_group, element) - values = parent_group.context.values.add(@id, @description.to_s, element) - context = TestContext.new(parent_group.context, ExampleHooks.empty, ExampleConditions.empty, values, {} of String => Deque(Mocks::MethodStub)) - NestedExampleGroup.new("#{@label} = #{element.inspect}", @source, parent_group, context).tap do |group| - group.children = children.map do |child| - child.build(group).as(ExampleComponent) - end - end - end - end -end