diff options
author | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-19 20:34:21 +0000 |
---|---|---|
committer | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-19 20:34:21 +0000 |
commit | 9bec8ef50ce1858ee2070a1637447eb12ce89990 (patch) | |
tree | e6cece58a34cf857c56e47bab13a5eeacd71af71 /lib/minitest/unit.rb | |
parent | 9cfc7a658f1e6f97fd88ee69310f4ccc5f20d73c (diff) | |
download | ruby-9bec8ef50ce1858ee2070a1637447eb12ce89990.tar.gz |
Imported minitest 2.6.2 (r6712)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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: |