Remove hooks, conditions, and sample vlues (for now)

Removed only from examples and example groups.
This commit is contained in:
Michael Miller 2019-09-08 10:28:02 -06:00
parent e304224bd6
commit de8f298676
3 changed files with 2 additions and 158 deletions

View file

@ -15,13 +15,8 @@ module Spectator
include Enumerable(ExampleComponent)
include Iterable(ExampleComponent)
getter sample_values : Internals::SampleValues
# Creates the example group.
# The hooks are stored to be triggered later.
def initialize(@hooks : ExampleHooks, @conditions : ExampleConditions, @sample_values)
@before_all_hooks_run = false
@after_all_hooks_run = false
def initialize
end
# Retrieves the children in the group.
@ -123,72 +118,5 @@ module Spectator
def finished?
children.all?(&.finished?)
end
# Runs all of the "before-each" and "before-all" hooks.
# This should run prior to every example in the group.
def run_before_hooks
run_before_all_hooks
run_before_each_hooks
end
# Runs all of the "before-all" hooks.
# This should run prior to any examples in the group.
# The hooks will be run only once.
# Subsequent calls to this method will do nothing.
protected def run_before_all_hooks : Nil
return if @before_all_hooks_run
@hooks.run_before_all
@before_all_hooks_run = true
end
# Runs all of the "before-each" hooks.
# This method should run prior to every example in the group.
protected def run_before_each_hooks : Nil
@hooks.run_before_each
end
# Runs all of the "after-all" and "after-each" hooks.
# This should run following every example in the group.
def run_after_hooks
run_after_each_hooks
run_after_all_hooks
end
# Runs all of the "after-all" hooks.
# This should run following all examples in the group.
# The hooks will be run only once,
# and only after all examples in the group have finished.
# Subsequent calls after the hooks have been run will do nothing.
protected def run_after_all_hooks(ignore_unfinished = false) : Nil
return if @after_all_hooks_run
return unless ignore_unfinished || finished?
@hooks.run_after_all
@after_all_hooks_run = true
end
# Runs all of the "after-each" hooks.
# This method should run following every example in the group.
protected def run_after_each_hooks : Nil
@hooks.run_after_each
end
# Creates a proc that runs the "around-each" hooks
# in addition to a block passed to this method.
# To call the block and all "around-each" hooks,
# just invoke `Proc#call` on the returned proc.
def wrap_around_each_hooks(&block : ->) : ->
@hooks.wrap_around_each(&block)
end
# Runs all of the pre-conditions for an example.
def run_pre_conditions
@conditions.run_pre_conditions
end
# Runs all of the post-conditions for an example.
def run_post_conditions
@conditions.run_post_conditions
end
end
end

View file

@ -18,8 +18,7 @@ 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, hooks : ExampleHooks, conditions : ExampleConditions, sample_values)
super(hooks, conditions, sample_values)
def initialize(@what, @parent)
end
# Indicates wheter the group references a type.
@ -27,69 +26,6 @@ module Spectator
@what.is_a?(Symbol)
end
# Runs all of the "before-all" hooks.
# This should run prior to any examples in the group.
# The hooks will be run only once.
# Subsequent calls to this method will do nothing.
# Parent "before-all" hooks will be run first.
protected def run_before_all_hooks : Nil
parent.run_before_all_hooks
super
end
# Runs all of the "before-each" hooks.
# This method should run prior to every example in the group.
# Parent "before-each" hooks will be run first.
protected def run_before_each_hooks : Nil
parent.run_before_each_hooks
super
end
# Runs all of the "after-all" hooks.
# This should run following all examples in the group.
# The hooks will be run only once,
# and only after all examples in the group have finished.
# Subsequent calls after the hooks have been run will do nothing.
# Parent "after-all" hooks will be run last.
protected def run_after_all_hooks(ignore_unfinished = false) : Nil
super
parent.run_after_all_hooks(ignore_unfinished)
end
# Runs all of the "after-each" hooks.
# This method should run following every example in the group.
# Parent "after-each" hooks will be run last.
protected def run_after_each_hooks : Nil
super
parent.run_after_each_hooks
end
# Creates a proc that runs the "around-each" hooks
# in addition to a block passed to this method.
# To call the block and all `around_each` hooks,
# just invoke `Proc#call` on the returned proc.
# Parent "around-each" hooks will be in the outermost wrappings.
def wrap_around_each_hooks(&block : ->) : ->
wrapper = super(&block)
parent.wrap_around_each_hooks(&wrapper)
end
# Runs all of the pre-condition checks.
# This method should run prior to every example in the group.
# Parent pre-conditions will be checked first.
def run_pre_conditions : Nil
parent.run_pre_conditions
super
end
# Runs all of the post-condition checks.
# This method should run following every example in the group.
# Parent post-conditions will be checked last.
def run_post_conditions : Nil
super
parent.run_post_conditions
end
# Creates a string representation of the group.
# The string consists of `#what` appended to the parent.
# This results in a string like:

View file

@ -17,22 +17,6 @@ module Spectator
# Runs the actual test code.
private abstract def run_instance
# Runs the hooks that should be performed before starting the test code.
private def run_before_hooks
group.run_before_hooks
rescue ex
# If an error occurs in the before hooks, skip running the example.
raise Exception.new("Error encountered while running before hooks", ex)
end
# Runs the hooks that should be performed after the test code finishes.
private def run_after_hooks
group.run_after_hooks
rescue ex
# If an error occurs in the after hooks, elevate it to abort testing.
raise Exception.new("Error encountered while running after hooks", ex)
end
# Runs all hooks and the example code.
# A captured result is returned.
private def capture_result
@ -40,9 +24,7 @@ module Spectator
# Get the proc that will call around-each hooks and the example.
wrapper = wrap_run_example(result)
run_before_hooks
run_wrapper(wrapper)
run_after_hooks
end
end
@ -70,9 +52,7 @@ module Spectator
# Capture how long it takes to run the test code.
result.elapsed = Time.measure do
begin
group.run_pre_conditions
run_instance # Actually run the example code.
group.run_post_conditions
rescue ex # Catch all errors and handle them later.
result.error = ex
end