mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add TestContext
This commit is contained in:
parent
da8736f891
commit
6e1605f246
6 changed files with 36 additions and 3 deletions
|
@ -33,6 +33,11 @@ module Spectator
|
|||
@example_count = children.sum(&.example_count)
|
||||
end
|
||||
|
||||
getter context
|
||||
|
||||
def initialize(@context : TestContext)
|
||||
end
|
||||
|
||||
# Yields each direct descendant.
|
||||
def each
|
||||
children.each do |child|
|
||||
|
|
|
@ -18,7 +18,8 @@ module Spectator
|
|||
# The parent's children must contain this group,
|
||||
# otherwise there may be unexpected behavior.
|
||||
# The *hooks* are stored to be triggered later.
|
||||
def initialize(@what, @parent)
|
||||
def initialize(@what, @parent, context)
|
||||
super(context)
|
||||
end
|
||||
|
||||
# Indicates wheter the group references a type.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require "../test_context"
|
||||
require "./example_builder"
|
||||
|
||||
module Spectator::SpecBuilder
|
||||
|
@ -31,6 +32,10 @@ module Spectator::SpecBuilder
|
|||
@after_all_hooks << hook
|
||||
end
|
||||
|
||||
private def context
|
||||
TestContext.new(build_hooks)
|
||||
end
|
||||
|
||||
private def build_hooks
|
||||
ExampleHooks.empty
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Spectator::SpecBuilder
|
|||
end
|
||||
|
||||
def build(group)
|
||||
NestedExampleGroup.new(@what, group).tap do |group|
|
||||
NestedExampleGroup.new(@what, group, context).tap do |group|
|
||||
group.children = children.map do |child|
|
||||
child.build(group).as(ExampleComponent)
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require "./example_group_builder"
|
|||
module Spectator::SpecBuilder
|
||||
class RootExampleGroupBuilder < ExampleGroupBuilder
|
||||
def build
|
||||
RootExampleGroup.new.tap do |group|
|
||||
RootExampleGroup.new(context).tap do |group|
|
||||
group.children = children.map do |child|
|
||||
child.build(group).as(ExampleComponent)
|
||||
end
|
||||
|
|
22
src/spectator/test_context.cr
Normal file
22
src/spectator/test_context.cr
Normal file
|
@ -0,0 +1,22 @@
|
|||
module Spectator
|
||||
struct TestContext
|
||||
def initialize(@hooks : ExampleHooks)
|
||||
@before_all_hooks_run = false
|
||||
@after_all_hooks_run = false
|
||||
end
|
||||
|
||||
def run_before_hooks(wrapper : TestWrapper)
|
||||
@hooks.run_before_all
|
||||
@hooks.run_before_each(wrapper)
|
||||
ensure
|
||||
@before_all_hooks_run = true
|
||||
end
|
||||
|
||||
def run_after_hooks(wrapper : TestWrapper)
|
||||
@hooks.run_after_each(wrapper)
|
||||
@hooks.run_after_all
|
||||
ensure
|
||||
@after_all_hooks_run = true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue