summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2007-12-05 13:42:13 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2007-12-05 13:42:13 +0100
commit17c8a9c07eb67c60174c762a15f5aebe8ee902c7 (patch)
treea420d13a57c87b63c83bce1cbf087005f685afb1
parent187e9d06e9f4255e9069a3fc3c7e232e07be8395 (diff)
downloadbacon-17c8a9c07eb67c60174c762a15f5aebe8ee902c7.tar.gz
bacon-17c8a9c07eb67c60174c762a15f5aebe8ee902c7.tar.xz
bacon-17c8a9c07eb67c60174c762a15f5aebe8ee902c7.zip
Allow using Object#should outside of contexts providing boolean return
darcs-hash:20071205124213-4fc50-3f808aaca8121e094097e1896c6ee2da3380649c.gz
-rw-r--r--lib/bacon.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb
index 80d5465..64e6504 100644
--- a/lib/bacon.rb
+++ b/lib/bacon.rb
@@ -138,6 +138,7 @@ module Bacon
     def run_requirement(description, spec)
       Bacon.handle_requirement description do
         begin
+          Bacon::Counter[:depth] += 1
           @before.each { |block| instance_eval(&block) }
           instance_eval(&spec)
           @after.each { |block| instance_eval(&block) }
@@ -158,6 +159,8 @@ module Bacon
           end
         else
           ""
+        ensure
+          Bacon::Counter[:depth] -= 1
         end
       end      
     end
@@ -275,10 +278,12 @@ class Should
     end
 
     r = yield(@object, *args)
-    unless @negated ^ r
-      raise Bacon::Error.new(:failed, description)
+    if Bacon::Counter[:depth] > 0
+      unless @negated ^ r
+        raise Bacon::Error.new(:failed, description)
+      end
+      Bacon::Counter[:requirements] += 1
     end
-    Bacon::Counter[:requirements] += 1
     @negated ^ r ? r : false
   end