diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-30 15:26:34 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-30 15:26:34 +0000 |
commit | 11caac16638cce5b5346e80246045897c33b0732 (patch) | |
tree | e7725721798a961007388c48828421ea97fa3665 | |
parent | b36b3067f0ed837e787753604e248085abde433c (diff) | |
download | ruby-11caac16638cce5b5346e80246045897c33b0732.tar.gz |
* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert):
assertion message must be String or Proc. suggested by caleb
clausen at [ruby-core:29884].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/test/unit/assertions.rb | 9 | ||||
-rw-r--r-- | test/testunit/test_assertion.rb | 8 |
3 files changed, 23 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Sat May 1 00:26:31 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/test/unit/assertions.rb (Test::Unit::Assertions#assert): + assertion message must be String or Proc. suggested by caleb + clausen at [ruby-core:29884]. + Sat May 1 00:14:47 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> * test/ruby/test_io.rb: skip false tests on Windows. diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb index 821faf5803..9a6d643623 100644 --- a/lib/test/unit/assertions.rb +++ b/lib/test/unit/assertions.rb @@ -10,6 +10,15 @@ module Test obj.pretty_inspect.chomp end + def assert(test, msg = (nomsg = true; nil)) + unless nomsg or msg.instance_of?(String) or msg.instance_of?(Proc) or + (bt = caller).shift.rindex(MiniTest::MINI_DIR, 0) + bt = MiniTest.filter_backtrace(bt) + raise ArgumentError, "assertion message must be String or Proc, but #{msg.class} was given.", bt + end + super + end + def assert_raise(*args, &b) assert_raises(*args, &b) end diff --git a/test/testunit/test_assertion.rb b/test/testunit/test_assertion.rb new file mode 100644 index 0000000000..374d6e022b --- /dev/null +++ b/test/testunit/test_assertion.rb @@ -0,0 +1,8 @@ +require 'test/unit' +class TestAssertion < Test::Unit::TestCase + def test_wrong_assertion + error, line = assert_raise(ArgumentError) {assert(true, true)}, __LINE__ + assert_match(/assertion message must be String or Proc, but TrueClass was given/, error.message) + assert_match(/\A#{Regexp.quote(__FILE__)}:#{line}:/, error.backtrace[0]) + end +end |