summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/test/unit/assertions.rb9
-rw-r--r--test/testunit/test_assertion.rb8
3 files changed, 23 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ac0e6dc3805..6547d1ed33a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 821faf5803a..9a6d6436234 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 00000000000..374d6e022bd
--- /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