From 00045ba9be4b76dbaed46a71cbcc660920695212 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 22 Apr 2019 20:27:54 -0600 Subject: [PATCH] Tests for nested groups and fail-fast --- spec/runner_spec.cr | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/spec/runner_spec.cr b/spec/runner_spec.cr index 7f75256..c2c4dfb 100644 --- a/spec/runner_spec.cr +++ b/spec/runner_spec.cr @@ -13,6 +13,18 @@ def new_test_suite(group : Spectator::ExampleGroup? = nil) Spectator::TestSuite.new(group || PassingExample.create.group, filter) end +def suite_with_nested_failures(hooks) + conditions = Spectator::ExampleConditions.empty + values = Spectator::Internals::SampleValues.empty + root = Spectator::RootExampleGroup.new(hooks, conditions) + root.children = Array(Spectator::ExampleComponent).new(5) do |index| + Spectator::NestedExampleGroup.new(index.to_s, root, hooks, conditions).tap do |group| + group.children = Array(Spectator::ExampleComponent).new(5) { FailingExample.new(group, values) } + end + end + new_test_suite(root) +end + describe Spectator::Runner do describe "#run" do it "runs all examples in the suite" do @@ -74,6 +86,39 @@ describe Spectator::Runner do called.should be_true end + context "with nested groups" do + it "runs after_each hooks" do + call_count = 0 + hooks = new_hooks(after_each: ->{ call_count += 1; nil }) + suite = suite_with_nested_failures(hooks) + runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true)) + runner.run + call_count.should eq(2) + end + + it "runs after_all hooks" do + call_count = 0 + hooks = new_hooks(after_all: ->{ call_count += 1; nil }) + suite = suite_with_nested_failures(hooks) + runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true)) + runner.run + call_count.should eq(2) + end + + it "runs the remaining around_each hook code" do + call_count = 0 + hooks = new_hooks(around_each: ->(proc : ->) { + proc.call + call_count += 1 + nil + }) + suite = suite_with_nested_failures(hooks) + runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true)) + runner.run + call_count.should eq(2) + end + end + context "the report" do it "has the remaining tests" do spy = SpyFormatter.new