mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Root group builder should not inherit from nested
This commit is contained in:
parent
30a45a24d3
commit
bff6d463df
4 changed files with 50 additions and 47 deletions
|
@ -2,7 +2,7 @@ module Spectator::DSL
|
|||
module Builder
|
||||
extend self
|
||||
|
||||
@@group_stack = Array(NestedExampleGroupBuilder).new(1, root_group)
|
||||
@@group_stack = Array(ExampleGroupBuilder).new(1, root_group)
|
||||
|
||||
private class_getter root_group = RootExampleGroupBuilder.new()
|
||||
|
||||
|
|
46
src/spectator/dsl/example_group_builder.cr
Normal file
46
src/spectator/dsl/example_group_builder.cr
Normal file
|
@ -0,0 +1,46 @@
|
|||
module Spectator::DSL
|
||||
abstract class ExampleGroupBuilder
|
||||
alias Child = ExampleFactory | NestedExampleGroupBuilder
|
||||
|
||||
@children = [] of Child
|
||||
@before_all_hooks = [] of ->
|
||||
@before_each_hooks = [] of ->
|
||||
@after_all_hooks = [] of ->
|
||||
@after_each_hooks = [] of ->
|
||||
@around_each_hooks = [] of Proc(Nil) ->
|
||||
|
||||
def add_child(child : Child)
|
||||
@children << child
|
||||
end
|
||||
|
||||
def add_before_all_hook(block : ->) : Nil
|
||||
@before_all_hooks << block
|
||||
end
|
||||
|
||||
def add_before_each_hook(block : ->) : Nil
|
||||
@before_each_hooks << block
|
||||
end
|
||||
|
||||
def add_after_all_hook(block : ->) : Nil
|
||||
@after_all_hooks << block
|
||||
end
|
||||
|
||||
def add_after_each_hook(block : ->) : Nil
|
||||
@after_each_hooks << block
|
||||
end
|
||||
|
||||
def add_around_each_hook(block : Proc(Nil) ->) : Nil
|
||||
@around_each_hooks << block
|
||||
end
|
||||
|
||||
private def build_hooks
|
||||
ExampleHooks.new(
|
||||
@before_all_hooks,
|
||||
@before_each_hooks,
|
||||
@after_all_hooks,
|
||||
@after_each_hooks,
|
||||
@around_each_hooks
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +1,5 @@
|
|||
module Spectator::DSL
|
||||
class NestedExampleGroupBuilder
|
||||
alias Child = ExampleFactory | NestedExampleGroupBuilder
|
||||
|
||||
@children = [] of Child
|
||||
@before_all_hooks = [] of ->
|
||||
@before_each_hooks = [] of ->
|
||||
@after_all_hooks = [] of ->
|
||||
@after_each_hooks = [] of ->
|
||||
@around_each_hooks = [] of Proc(Nil) ->
|
||||
|
||||
class NestedExampleGroupBuilder < ExampleGroupBuilder
|
||||
def initialize(@what : String)
|
||||
end
|
||||
|
||||
|
@ -16,42 +7,12 @@ module Spectator::DSL
|
|||
@children << child
|
||||
end
|
||||
|
||||
def add_before_all_hook(block : ->) : Nil
|
||||
@before_all_hooks << block
|
||||
end
|
||||
|
||||
def add_before_each_hook(block : ->) : Nil
|
||||
@before_each_hooks << block
|
||||
end
|
||||
|
||||
def add_after_all_hook(block : ->) : Nil
|
||||
@after_all_hooks << block
|
||||
end
|
||||
|
||||
def add_after_each_hook(block : ->) : Nil
|
||||
@after_each_hooks << block
|
||||
end
|
||||
|
||||
def add_around_each_hook(block : Proc(Nil) ->) : Nil
|
||||
@around_each_hooks << block
|
||||
end
|
||||
|
||||
def build(parent : ExampleGroup, sample_values : Internals::SampleValues) : ExampleGroup
|
||||
def build(parent : ExampleGroup, sample_values : Internals::SampleValues) : NestedExampleGroup
|
||||
NestedExampleGroup.new(@what, parent, build_hooks).tap do |group|
|
||||
group.children = @children.map do |child|
|
||||
child.build(group, sample_values).as(ExampleComponent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private def build_hooks
|
||||
ExampleHooks.new(
|
||||
@before_all_hooks,
|
||||
@before_each_hooks,
|
||||
@after_all_hooks,
|
||||
@after_each_hooks,
|
||||
@around_each_hooks
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
module Spectator::DSL
|
||||
class RootExampleGroupBuilder < NestedExampleGroupBuilder
|
||||
def initialize
|
||||
super("ROOT")
|
||||
end
|
||||
|
||||
class RootExampleGroupBuilder < ExampleGroupBuilder
|
||||
def build(sample_values : Internals::SampleValues) : RootExampleGroup
|
||||
RootExampleGroup.new(build_hooks).tap do |group|
|
||||
group.children = @children.map do |child|
|
||||
|
|
Loading…
Reference in a new issue