From 17c8a9c07eb67c60174c762a15f5aebe8ee902c7 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Wed, 5 Dec 2007 13:42:13 +0100 Subject: Allow using Object#should outside of contexts providing boolean return darcs-hash:20071205124213-4fc50-3f808aaca8121e094097e1896c6ee2da3380649c.gz --- lib/bacon.rb | 11 ++++++++--- 1 file 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 -- cgit 1.4.1