diff --git a/spec/helpers/failing_example.cr b/spec/helpers/failing_example.cr index 706396b..25cd460 100644 --- a/spec/helpers/failing_example.cr +++ b/spec/helpers/failing_example.cr @@ -33,4 +33,12 @@ class FailingExample < Spectator::RunnableExample group.children = [example.as(Spectator::ExampleComponent)] end end + + # Creates a group of failing examples. + def self.create_group(count = 5, hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty) + values = Spectator::Internals::SampleValues.empty + Spectator::RootExampleGroup.new(hooks, conditions).tap do |group| + group.children = Array.new(count) { new(group, values).as(Spectator::ExampleComponent) } + end + end end diff --git a/spec/runner_spec.cr b/spec/runner_spec.cr index 62759d8..7f75256 100644 --- a/spec/runner_spec.cr +++ b/spec/runner_spec.cr @@ -40,6 +40,40 @@ describe Spectator::Runner do called.should eq([0, 1, 2, 3, 4, 5, 6]) end + it "runs after_each hooks" do + called = false + hooks = new_hooks(after_each: ->{ called = true; nil }) + group = FailingExample.create_group(hooks: hooks) + suite = new_test_suite(group) + runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true)) + runner.run + called.should be_true + end + + it "runs after_all hooks" do + called = false + hooks = new_hooks(after_all: ->{ called = true; nil }) + group = FailingExample.create_group(hooks: hooks) + suite = new_test_suite(group) + runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true)) + runner.run + called.should be_true + end + + it "runs the remaining around_each hook code" do + called = false + hooks = new_hooks(around_each: ->(proc : ->) { + proc.call + called = true + nil + }) + group = FailingExample.create_group(hooks: hooks) + suite = new_test_suite(group) + runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true)) + runner.run + called.should be_true + end + context "the report" do it "has the remaining tests" do spy = SpyFormatter.new