From ef12e3967bc4a7814df3bbee0764c3960022ff53 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 7 Dec 2018 23:07:04 -0700 Subject: [PATCH] Add checks for cause of hook error Fix some tests that had copy/paste mistakes. --- spec/runnable_example_spec.cr | 54 +++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/spec/runnable_example_spec.cr b/spec/runnable_example_spec.cr index 4ac5b22..2c79b86 100644 --- a/spec/runnable_example_spec.cr +++ b/spec/runnable_example_spec.cr @@ -532,6 +532,16 @@ describe Spectator::RunnableExample do end end + it "passes along the original exception" do + error = Exception.new("oops") + hooks = new_hooks(before_all: ->{ raise error; nil }) + begin + run_example(PassingExample, hooks) + rescue ex + ex.cause.should eq(error) + end + end + it "doesn't run the test code" do called = false hooks = new_hooks(before_all: ->{ raise "oops"; nil }) @@ -578,6 +588,16 @@ describe Spectator::RunnableExample do end end + it "passes along the original exception" do + error = Exception.new("oops") + hooks = new_hooks(before_each: ->{ raise error; nil }) + begin + run_example(PassingExample, hooks) + rescue ex + ex.cause.should eq(error) + end + end + it "doesn't run the test code" do called = false hooks = new_hooks(before_each: ->{ raise "oops"; nil }) @@ -617,15 +637,25 @@ describe Spectator::RunnableExample do context "when an error is raised in an after_all hook" do it "raises the exception" do - hooks = new_hooks(before_all: ->{ raise "oops"; nil }) + hooks = new_hooks(after_all: ->{ raise "oops"; nil }) expect_raises(Exception) do run_example(PassingExample, hooks) end end + it "passes along the original exception" do + error = Exception.new("oops") + hooks = new_hooks(after_all: ->{ raise error; nil }) + begin + run_example(PassingExample, hooks) + rescue ex + ex.cause.should eq(error) + end + end + it "doesn't run any additional after_all hooks" do called = false - hooks = new_hooks(before_all: [ + hooks = new_hooks(after_all: [ ->{ raise "oops"; nil }, ->{ called = true; nil }, ]) @@ -644,6 +674,16 @@ describe Spectator::RunnableExample do end end + it "passes along the original exception" do + error = Exception.new("oops") + hooks = new_hooks(after_each: ->{ raise error; nil }) + begin + run_example(PassingExample, hooks) + rescue ex + ex.cause.should eq(error) + end + end + it "doesn't run any additional after_each hooks" do called = false hooks = new_hooks(after_each: [ @@ -679,6 +719,16 @@ describe Spectator::RunnableExample do end end + it "passes along the original exception" do + error = Exception.new("oops") + hooks = new_hooks(around_each: ->(proc : ->) { raise error; proc.call }) + begin + run_example(PassingExample, hooks) + rescue ex + ex.cause.should eq(error) + end + end + it "doesn't run the test code" do called = false hooks = new_hooks(around_each: ->(proc : ->) { raise "oops"; proc.call })