summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2008-03-02 11:52:38 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2008-03-02 11:52:38 +0100
commitf308996c1e63a3ccdd8017fa9095e41aa91d756b (patch)
treeeec3f18739f34c9841466d161e6138f14131883c
parenteae20f9918990779d47720b464ba14042e1bfc86 (diff)
downloadbacon-f308996c1e63a3ccdd8017fa9095e41aa91d756b.tar.gz
bacon-f308996c1e63a3ccdd8017fa9095e41aa91d756b.tar.xz
bacon-f308996c1e63a3ccdd8017fa9095e41aa91d756b.zip
Call after-blocks even if before-blocks or spec raise exceptions
Based on a patch by Keita Yamaguchi

darcs-hash:20080302105238-4fc50-109b938f91a842da8c04469af9edc7aed9766e51.gz
-rw-r--r--lib/bacon.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb
index 0547249..fcb3bbe 100644
--- a/lib/bacon.rb
+++ b/lib/bacon.rb
@@ -139,14 +139,25 @@ module Bacon
       Bacon.handle_requirement description do
         begin
           Counter[:depth] += 1
-          @before.each { |block| instance_eval(&block) }
-          prev_req = Counter[:requirements]
-          instance_eval(&spec)
-          if Counter[:requirements] == prev_req
-            raise Error.new(:missing,
-                            "empty specification: #{@name} #{description}")
+          rescued = false
+          begin
+            @before.each { |block| instance_eval(&block) }
+            prev_req = Counter[:requirements]
+            instance_eval(&spec)
+          rescue Object => e
+            rescued = true
+            raise e
+          ensure
+            if Counter[:requirements] == prev_req
+              raise Error.new(:missing,
+                              "empty specification: #{@name} #{description}")
+            end
+            begin
+              @after.each { |block| instance_eval(&block) }
+            rescue Object => e
+              raise e  unless rescued
+            end
           end
-          @after.each { |block| instance_eval(&block) }
         rescue Object => e
           ErrorLog << "#{e.class}: #{e.message}\n"
           e.backtrace.find_all { |line| line !~ /bin\/bacon|\/bacon\.rb:\d+/ }.