summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2007-05-31 14:17:05 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2007-05-31 14:17:05 +0200
commit30102c7c3859053e23228bb5f93c9410a4930e56 (patch)
tree22bea1f5701af89b6ea809163f9aa2436cdbe715 /lib
parent55ac89c3f25e7a24fa5306e400af76483d2144ce (diff)
downloadbacon-30102c7c3859053e23228bb5f93c9410a4930e56.tar.gz
bacon-30102c7c3859053e23228bb5f93c9410a4930e56.tar.xz
bacon-30102c7c3859053e23228bb5f93c9410a4930e56.zip
Fix for testsuite
darcs-hash:20070531121705-4fc50-bdc3919a301da12ee024b9d2508d8139ea5c8d09.gz
Diffstat (limited to 'lib')
-rw-r--r--lib/bacon.rb56
1 files changed, 44 insertions, 12 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb
index ccf7427..200aab9 100644
--- a/lib/bacon.rb
+++ b/lib/bacon.rb
@@ -74,11 +74,15 @@ module Bacon
           else
             Bacon::Counter[:errors] += 1
             "ERROR: #{e.class}"
-        end
+          end
         else
           ""
         end
-      end
+      end      
+    end
+
+    def raise?(*args, &block)
+      block.raise?(*args)
     end
   end
 end
@@ -100,15 +104,22 @@ end
 class Proc
   def raise?(*exceptions)
     call
-  rescue *(exceptions.empty? ? RuntimeError : exceptions)
-    true
-  rescue
-    false
+  rescue *(exceptions.empty? ? RuntimeError : exceptions) => e
+    e
+  # do not rescue other exceptions.
   else
     false
   end
 end
 
+class Float
+  def close?(to, delta)
+    (to.to_f - self).abs <= delta.to_f
+  rescue
+    false
+  end
+end
+
 class Object
   def should(*args, &block)
     Should.new(self).be(*args, &block)
@@ -119,6 +130,7 @@ class Object
   end
 end
 
+
 class Should
   # Kills ==, ===, =~, eql?, equal?, frozen?, instance_of?, is_a?,
   # kind_of?, nil?, respond_to?, tainted?
@@ -131,9 +143,14 @@ class Should
     @negated = false
   end
 
-  def not
+  def not(*args, &block)
     @negated = !@negated
-    self
+    
+    if args.empty?
+      self
+    else
+      be(*args, &block)
+    end
   end
 
   def be(*args, &block)
@@ -150,17 +167,32 @@ class Should
   alias an be
   
   def satisfy(*args, &block)
-    unless @negated ^ yield(@object, *args)
-      raise Bacon::Error.new(:failed, "")
+    if args.size == 1 && String === args.first
+      description = args.shift
+    else
+      description = ""
+    end
+
+    r = yield(@object, *args)
+    unless @negated ^ r
+      raise Bacon::Error.new(:failed, description)
     end
     Bacon::Counter[:requirements] += 1
     @negated ^ r ? r : false
   end
 
   def method_missing(name, *args, &block)
-    satisfy { |x|
-      name = "#{name}?"  if name.to_s =~ /\w/
+    name = "#{name}?"  if name.to_s =~ /\w/
+    
+    desc = @negated ? "not " : ""
+    desc << @object.inspect << "." << name.to_s
+    desc << "(" << args.map{|x|x.inspect}.join(", ") << ")"
+      
+    satisfy(desc) { |x|
       x.__send__(name, *args, &block)
     }
   end
+
+  def equal(value); self == value; end
+  def match(value); self =~ value; end
 end