diff options
Diffstat (limited to 'lib/minitest/unit.rb')
-rw-r--r-- | lib/minitest/unit.rb | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/lib/minitest/unit.rb b/lib/minitest/unit.rb index 922ef70183..38e3f3a83e 100644 --- a/lib/minitest/unit.rb +++ b/lib/minitest/unit.rb @@ -24,7 +24,7 @@ module MiniTest class Skip < Assertion; end - file = if RUBY_VERSION =~ /^1\.9/ then # bt's expanded, but __FILE__ isn't :( + file = if RUBY_VERSION >= '1.9.0' then # bt's expanded, but __FILE__ isn't :( File.expand_path __FILE__ elsif __FILE__ =~ /^[^\.]/ then # assume both relative require 'pathname' @@ -253,7 +253,7 @@ module MiniTest end ## - # Fails unless +obj+ is an instace of +cls+. + # Fails unless +obj+ is an instance of +cls+. def assert_instance_of cls, obj, msg = nil msg = message(msg) { @@ -291,12 +291,16 @@ module MiniTest assert obj.nil?, msg end + UNDEFINED = Object.new + def UNDEFINED.inspect; "UNDEFINED"; end + ## - # For testing equality operators and so-forth. + # For testing with binary operators. # # assert_operator 5, :<=, 4 - def assert_operator o1, op, o2, msg = nil + def assert_operator o1, op, o2 = UNDEFINED, msg = nil + return assert_predicate o1, op, msg if UNDEFINED == o2 msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op} #{mu_pp(o2)}" } assert o1.__send__(op, o2), msg end @@ -320,6 +324,20 @@ module MiniTest end ## + # For testing with predicates. + # + # assert_predicate str, :empty? + # + # This is really meant for specs and is front-ended by assert_operator: + # + # str.must_be :empty? + + def assert_predicate o1, op, msg = nil + msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op}" } + assert o1.__send__(op), msg + end + + ## # Fails unless the block raises one of +exp+ def assert_raises *exp @@ -582,14 +600,27 @@ module MiniTest # refute_operator 1, :>, 2 #=> pass # refute_operator 1, :<, 2 #=> fail - def refute_operator o1, op, o2, msg = nil - msg = message(msg) { - "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}" - } + def refute_operator o1, op, o2 = UNDEFINED, msg = nil + return refute_predicate o1, op, msg if UNDEFINED == o2 + msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}"} refute o1.__send__(op, o2), msg end ## + # For testing with predicates. + # + # refute_predicate str, :empty? + # + # This is really meant for specs and is front-ended by refute_operator: + # + # str.wont_be :empty? + + def refute_predicate o1, op, msg = nil + msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op}" } + refute o1.__send__(op), msg + end + + ## # Fails if +obj+ responds to the message +meth+. def refute_respond_to obj, meth, msg = nil @@ -620,7 +651,7 @@ module MiniTest end class Unit - VERSION = "2.5.1" # :nodoc: + VERSION = "2.6.1" # :nodoc: attr_accessor :report, :failures, :errors, :skips # :nodoc: attr_accessor :test_count, :assertion_count # :nodoc: |