mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Call parent hooks
This commit is contained in:
parent
957b8a54db
commit
db3f89731c
4 changed files with 31 additions and 8 deletions
|
@ -32,10 +32,6 @@ module Spectator::SpecBuilder
|
|||
@after_all_hooks << hook
|
||||
end
|
||||
|
||||
private def context
|
||||
TestContext.new(build_hooks)
|
||||
end
|
||||
|
||||
private def build_hooks
|
||||
ExampleHooks.new(
|
||||
@before_all_hooks.to_a,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require "../test_context"
|
||||
require "./example_group_builder"
|
||||
|
||||
module Spectator::SpecBuilder
|
||||
|
@ -6,6 +7,7 @@ module Spectator::SpecBuilder
|
|||
end
|
||||
|
||||
def build(group)
|
||||
context = TestContext.new(group.context, build_hooks)
|
||||
NestedExampleGroup.new(@what, group, context).tap do |group|
|
||||
group.children = children.map do |child|
|
||||
child.build(group).as(ExampleComponent)
|
||||
|
|
|
@ -3,6 +3,7 @@ require "./example_group_builder"
|
|||
module Spectator::SpecBuilder
|
||||
class RootExampleGroupBuilder < ExampleGroupBuilder
|
||||
def build
|
||||
context = TestContext.new(nil, build_hooks)
|
||||
RootExampleGroup.new(context).tap do |group|
|
||||
group.children = children.map do |child|
|
||||
child.build(group).as(ExampleComponent)
|
||||
|
|
|
@ -1,22 +1,46 @@
|
|||
module Spectator
|
||||
struct TestContext
|
||||
def initialize(@hooks : ExampleHooks)
|
||||
class TestContext
|
||||
def initialize(@parent : TestContext?, @hooks : ExampleHooks)
|
||||
@before_all_hooks_run = false
|
||||
@after_all_hooks_run = false
|
||||
end
|
||||
|
||||
def run_before_hooks(wrapper : TestWrapper)
|
||||
run_before_all_hooks
|
||||
run_before_each_hooks(wrapper)
|
||||
end
|
||||
|
||||
protected def run_before_all_hooks
|
||||
return if @before_all_hooks_run
|
||||
|
||||
@parent.try &.run_before_all_hooks
|
||||
@hooks.run_before_all
|
||||
@hooks.run_before_each(wrapper)
|
||||
ensure
|
||||
@before_all_hooks_run = true
|
||||
end
|
||||
|
||||
protected def run_before_each_hooks(wrapper : TestWrapper)
|
||||
@parent.try &.run_before_each_hooks(wrapper)
|
||||
@hooks.run_before_each(wrapper)
|
||||
end
|
||||
|
||||
def run_after_hooks(wrapper : TestWrapper)
|
||||
@hooks.run_after_each(wrapper)
|
||||
run_after_each_hooks(wrapper)
|
||||
run_after_all_hooks
|
||||
end
|
||||
|
||||
protected def run_after_all_hooks
|
||||
return if @after_all_hooks_run
|
||||
|
||||
@hooks.run_after_all
|
||||
@parent.try &.run_after_all_hooks
|
||||
ensure
|
||||
@after_all_hooks_run = true
|
||||
end
|
||||
|
||||
protected def run_after_each_hooks(wrapper : TestWrapper)
|
||||
@hooks.run_after_each(wrapper)
|
||||
@parent.try &.run_after_each_hooks(wrapper)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue