mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove SpecBuilder types
This commit is contained in:
parent
8b205278ad
commit
6e3ec79a14
8 changed files with 0 additions and 204 deletions
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
Loading…
Reference in a new issue