diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-09-12 03:40:49 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-09-12 03:40:49 +0000 |
commit | 1161616768dba3ba8470cd8877b01a2c3ce80a3d (patch) | |
tree | 46d15416549e55982ba2267ee9a11bf4487853ca | |
parent | 776227cbcfde1e583a1b12014fdb7dc1f569724a (diff) | |
download | ruby-1161616768dba3ba8470cd8877b01a2c3ce80a3d.tar.gz |
* lib/test/unit/assertions.rb (assert_send): make arguments in
the default message clearer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33251 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/test/unit/assertions.rb | 52 |
2 files changed, 57 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Mon Sep 12 12:40:44 2011 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/test/unit/assertions.rb (assert_send): make arguments in + the default message clearer. + Sun Sep 11 05:23:14 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca> * lib/matrix.rb: Deal with subclasses of Matrix [redmine #5307] diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb index b023a778b6..566b4f4b8e 100644 --- a/lib/test/unit/assertions.rb +++ b/lib/test/unit/assertions.rb @@ -253,6 +253,58 @@ EOT super if !caller[0].rindex(MiniTest::MINI_DIR, 0) || !obj.respond_to?(meth) end + # :call-seq: + # assert_send( +send_array+, failure_message = nil ) + # + # Passes if the method send returns a true value. + # + # +send_array+ is composed of: + # * A receiver + # * A method + # * Arguments to the method + # + # Example: + # assert_send([[1, 2], :member?, 1]) # -> pass + # assert_send([[1, 2], :member?, 4]) # -> fail + def assert_send send_ary, m = nil + recv, msg, *args = send_ary + m = message(m) { + if args.empty? + argsstr = "" + else + (argsstr = mu_pp(args)).sub!(/\A\[(.*)\]\z/m, '\1') + end + "Expected #{mu_pp(recv)}.#{msg}#{argsstr} to return false" + } + assert recv.__send__(msg, *args), m + end + + # :call-seq: + # assert_not_send( +send_array+, failure_message = nil ) + # + # Passes if the method send doesn't return a true value. + # + # +send_array+ is composed of: + # * A receiver + # * A method + # * Arguments to the method + # + # Example: + # assert_not_send([[1, 2], :member?, 1]) # -> fail + # assert_not_send([[1, 2], :member?, 4]) # -> pass + def assert_not_send send_ary, m = nil + recv, msg, *args = send_ary + m = message(m) { + if args.empty? + argsstr = "" + else + (argsstr = mu_pp(args)).sub!(/\A\[(.*)\]\z/m, '\1') + end + "Expected #{mu_pp(recv)}.#{msg}#{argsstr} to return false" + } + assert !recv.__send__(msg, *args), m + end + ms = instance_methods(true).map {|sym| sym.to_s } ms.grep(/\Arefute_/) do |m| mname = ('assert_not_' << m.to_s[/.*?_(.*)/, 1]) |