summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--lib/minitest/unit.rb6
-rw-r--r--test/minitest/test_mini_test.rb34
3 files changed, 32 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 3c058898d1..90eb3a6c9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Fri Jan 16 13:28:09 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
+
+ * test/minitest/test_mini_test.rb: the number of assertions must be
+ exactly equal to the number of assertion method calls that the end-user
+ would write. [ruby-dev:37703]
+
+ * lib/minitest/unit.rb: ditto.
+ Patch by David Flanagan <david AT davidflanagan.com>. [ruby-core:21350]
+
Fri Jan 16 12:24:39 2009 Koichi Sasada <ko1@atdot.net>
* thread.c (thread_start_func_2): call ruby_cleanup() if thread is
diff --git a/lib/minitest/unit.rb b/lib/minitest/unit.rb
index 5f2fa5c99e..77bcee99ee 100644
--- a/lib/minitest/unit.rb
+++ b/lib/minitest/unit.rb
@@ -76,6 +76,7 @@ module MiniTest
def assert_empty obj, msg = nil
msg = message(msg) { "Expected #{obj.inspect} to be empty" }
assert_respond_to obj, :empty?
+ self._assertions -= 1
assert obj.empty?, msg
end
@@ -97,6 +98,7 @@ module MiniTest
def assert_includes collection, obj, msg = nil
msg = message(msg) { "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}" }
assert_respond_to collection, :include?
+ self._assertions -= 1
assert collection.include?(obj), msg
end
@@ -118,6 +120,7 @@ module MiniTest
def assert_match exp, act, msg = nil
msg = message(msg) { "Expected #{mu_pp(exp)} to match #{mu_pp(act)}" }
assert_respond_to act, :"=~"
+ self._assertions -= 1
exp = /#{Regexp.escape(exp)}/ if String === exp && String === act
assert exp =~ act, msg
end
@@ -241,6 +244,7 @@ module MiniTest
def refute_empty obj, msg = nil
msg = message(msg) { "Expected #{obj.inspect} to not be empty" }
assert_respond_to obj, :empty?
+ self._assertions -= 1
refute obj.empty?, msg
end
@@ -262,6 +266,7 @@ module MiniTest
def refute_includes collection, obj, msg = nil
msg = message(msg) { "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}" }
assert_respond_to collection, :include?
+ self._assertions -= 1
refute collection.include?(obj), msg
end
@@ -282,6 +287,7 @@ module MiniTest
def refute_match exp, act, msg = nil
msg = message(msg) { "Expected #{mu_pp(exp)} to not match #{mu_pp(act)}" }
assert_respond_to act, :"=~"
+ self._assertions -= 1
exp = /#{Regexp.escape(exp)}/ if String === exp && String === act
refute exp =~ act, msg
end
diff --git a/test/minitest/test_mini_test.rb b/test/minitest/test_mini_test.rb
index 046ae66d88..e064ec2544 100644
--- a/test/minitest/test_mini_test.rb
+++ b/test/minitest/test_mini_test.rb
@@ -440,13 +440,13 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_empty
- @assertion_count = 2
+ @assertion_count = 1
@tc.assert_empty []
end
def test_assert_empty_triggered
- @assertion_count = 2
+ @assertion_count = 1
util_assert_triggered "Expected [1] to be empty." do
@tc.assert_empty [1]
@@ -494,13 +494,13 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_includes
- @assertion_count = 2
+ @assertion_count = 1
@tc.assert_includes [true], true
end
def test_assert_includes_triggered
- @assertion_count = 3
+ @assertion_count = 2
e = @tc.assert_raises MiniTest::Assertion do
@tc.assert_includes [true], false
@@ -531,12 +531,12 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_match
- @assertion_count = 2
+ @assertion_count = 1
@tc.assert_match(/\w+/, "blah blah blah")
end
def test_assert_match_object
- @assertion_count = 2
+ @assertion_count = 1
pattern = Object.new
def pattern.=~(other) true end
@@ -545,7 +545,7 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_match_object_triggered
- @assertion_count = 2
+ @assertion_count = 1
pattern = Object.new
def pattern.=~(other) false end
@@ -557,7 +557,7 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_match_triggered
- @assertion_count = 2
+ @assertion_count = 1
util_assert_triggered 'Expected /\d+/ to match "blah blah blah".' do
@tc.assert_match(/\d+/, "blah blah blah")
end
@@ -801,13 +801,13 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
end
def test_refute_empty
- @assertion_count = 2
+ @assertion_count = 1
@tc.refute_empty [1]
end
def test_refute_empty_triggered
- @assertion_count = 2
+ @assertion_count = 1
util_assert_triggered "Expected [] to not be empty." do
@tc.refute_empty []
@@ -846,13 +846,13 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
end
def test_refute_includes
- @assertion_count = 2
+ @assertion_count = 1
@tc.refute_includes [true], false
end
def test_refute_includes_triggered
- @assertion_count = 3
+ @assertion_count = 2
e = @tc.assert_raises MiniTest::Assertion do
@tc.refute_includes [true], true
@@ -883,17 +883,17 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
end
def test_refute_match
- @assertion_count = 2
+ @assertion_count = 1
@tc.refute_match(/\d+/, "blah blah blah")
end
def test_refute_match_object
- @assertion_count = 2
+ @assertion_count = 1
@tc.refute_match Object.new, 5 # default #=~ returns false
end
def test_assert_object_triggered
- @assertion_count = 2
+ @assertion_count = 1
pattern = Object.new
def pattern.=~(other) false end
@@ -905,7 +905,7 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
end
def test_refute_match_object_triggered
- @assertion_count = 2
+ @assertion_count = 1
pattern = Object.new
def pattern.=~(other) true end
@@ -917,7 +917,7 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
end
def test_refute_match_triggered
- @assertion_count = 2
+ @assertion_count = 1
util_assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do
@tc.refute_match(/\w+/, "blah blah blah")
end