lib/dfect/unit.rb in dfect-1.0.0 vs lib/dfect/unit.rb in dfect-1.1.0

- old
+ new

@@ -1,9 +1,9 @@ # Test::Unit emulation layer. #-- -# Copyright 2009 Suraj N. Kurapati -# See the LICENSE file for details. +# Copyright protects this work. +# See LICENSE file for details. #++ require 'dfect' module Kernel @@ -18,10 +18,15 @@ [ [:assert, nil, nil ], [:assert_not, '!', 'not '], ]. each do |prefix, polarity, action| + # + # XXX: using eval() because Ruby 1.8 does + # not support default values and + # block parameters in define_method() + # file, line = __FILE__, __LINE__ ; eval %{ def #{prefix} boolean, message = nil Dfect.T#{polarity}(message) { boolean } end @@ -32,19 +37,21 @@ def #{prefix}_empty collection, message = nil message ||= 'collection must #{action}be empty' Dfect.T#{polarity}(message) { collection.empty? } end - def #{prefix}_equal actual, expected, message = nil + def #{prefix}_equal expected, actual, message = nil message ||= 'actual must #{action}equal expected' Dfect.T#{polarity}(message) { actual == expected } end def #{prefix}_in_delta expected, actual, delta = nil, message = nil message ||= 'actual must #{action}be within delta of expected' delta ||= 0.001 - Dfect.T#{polarity}(message) { Math.abs(expected - actual) <= Math.abs(delta) } + Dfect.T#{polarity}(message) do + Math.abs(expected - actual) <= Math.abs(delta) + end end alias #{prefix}_in_epsilon #{prefix}_in_delta def #{prefix}_include item, collection, message = nil