summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/minitest/unit.rb23
-rw-r--r--test/minitest/test_mini_spec.rb17
-rw-r--r--test/minitest/test_mini_test.rb54
4 files changed, 67 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index bd8a975d55..7624590906 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Oct 26 07:35:56 2008 Ryan Davis <ryan@wrath.local>
+
+ * lib/minitest/unit.rb: Imported minitest 1.3.0 r4429.
+ * test/minitest/*: ditto.
+
Sun Oct 26 02:16:29 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* configure.in ($MANTYPE): followed ruby.1, which had moved.
diff --git a/lib/minitest/unit.rb b/lib/minitest/unit.rb
index ad9e3c4305..460258cdf2 100644
--- a/lib/minitest/unit.rb
+++ b/lib/minitest/unit.rb
@@ -87,7 +87,7 @@ module MiniTest
def assert_in_delta exp, act, delta = 0.001, msg = nil
n = (exp - act).abs
msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to be < #{delta}" }
- assert delta > n, msg
+ assert delta >= n, msg
end
def assert_in_epsilon a, b, epsilon = 0.001, msg = nil
@@ -139,7 +139,10 @@ module MiniTest
yield
should_raise = true
rescue Exception => e
- assert_includes(exp, e.class, exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
+ assert(exp.any? { |ex|
+ ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
+ }, exception_details(e, "#{mu_pp(exp)} exception expected, not"))
+
return e
end
@@ -188,12 +191,12 @@ module MiniTest
assert caught, message(msg) { default }
end
- def capture_io
- require 'stringio'
+ def capture_io
+ require 'stringio'
- orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
- captured_stdout, captured_stderr = StringIO.new, StringIO.new
- $stdout, $stderr = captured_stdout, captured_stderr
+ orig_stdout, orig_stderr = $stdout, $stderr
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
+ $stdout, $stderr = captured_stdout, captured_stderr
yield
@@ -303,14 +306,14 @@ module MiniTest
refute exp.equal?(act), msg
end
- def skip msg = nil
+ def skip msg = nil, bt = caller
msg ||= "Skipped, no message given"
- raise MiniTest::Skip, msg
+ raise MiniTest::Skip, msg, bt
end
end
class Unit
- VERSION = "1.3.0"
+ VERSION = "1.3.1"
attr_accessor :report, :failures, :errors, :skips
attr_accessor :test_count, :assertion_count
diff --git a/test/minitest/test_mini_spec.rb b/test/minitest/test_mini_spec.rb
index fd7be50dac..4fe5bad048 100644
--- a/test/minitest/test_mini_spec.rb
+++ b/test/minitest/test_mini_spec.rb
@@ -10,7 +10,7 @@ MiniTest::Unit.autorun
describe MiniTest::Spec do
before do
- @assertion_count = 5
+ @assertion_count = 4
end
after do
@@ -65,7 +65,7 @@ describe MiniTest::Spec do
end
it "needs to verify kinds of objects" do
- @assertion_count = 7
+ @assertion_count = 6
(6 * 7).must_be_kind_of(Fixnum).must_equal true
(6 * 7).must_be_kind_of(Numeric).must_equal true
@@ -73,7 +73,8 @@ describe MiniTest::Spec do
end
it "needs to verify regexp matches" do
- @assertion_count = 7
+ @assertion_count = 6
+
"blah".must_match(/\w+/).must_equal true
proc { "blah".must_match(/\d+/) }.must_raise MiniTest::Assertion
end
@@ -89,14 +90,14 @@ describe MiniTest::Spec do
end
it "needs to catch an expected exception" do
- @assertion_count = 4
+ @assertion_count = 2
proc { raise "blah" }.must_raise RuntimeError
proc { raise MiniTest::Assertion }.must_raise MiniTest::Assertion
end
it "needs to catch an unexpected exception" do
- @assertion_count = 4
+ @assertion_count = 2
proc {
proc { raise MiniTest::Assertion }.must_raise(RuntimeError)
@@ -104,13 +105,13 @@ describe MiniTest::Spec do
end
it "needs raise if an expected exception is not raised" do
- @assertion_count = 3
+ @assertion_count = 2
proc { proc { 42 }.must_raise(RuntimeError) }.must_raise MiniTest::Assertion
end
it "needs to be able to catch a MiniTest::Assertion exception" do
- @assertion_count = 3
+ @assertion_count = 2
proc { 1.wont_equal 1 }.must_raise MiniTest::Assertion
end
@@ -126,7 +127,7 @@ describe MiniTest::Spec do
end
it "needs to verify throw" do
- @assertion_count = 8
+ @assertion_count = 6
proc { throw :blah }.must_throw(:blah).must_equal true
proc { proc { }.must_throw(:blah) }.must_raise MiniTest::Assertion
diff --git a/test/minitest/test_mini_test.rb b/test/minitest/test_mini_test.rb
index f5a48cb535..8561acb5bf 100644
--- a/test/minitest/test_mini_test.rb
+++ b/test/minitest/test_mini_test.rb
@@ -9,8 +9,10 @@ require 'minitest/unit'
MiniTest::Unit.autorun
-class TestMiniTest < MiniTest::Unit::TestCase
+module M; end
+class E < StandardError; include M; end
+class TestMiniTest < MiniTest::Unit::TestCase
def setup
srand 42
MiniTest::Unit::TestCase.reset
@@ -248,10 +250,10 @@ Finished in 0.00
"
output = @output.string.sub(/Finished in .*/, "Finished in 0.00")
output.sub!(/Loaded suite .*/, 'Loaded suite blah')
- output.sub!(/[\w\/\.]+:\d+/, 'FILE:LINE')
+ output.sub!(/^(\s+)(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+:/o, '\1FILE:LINE:')
+ output.sub!(/\[(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+\]/o, '[FILE:LINE]')
assert_equal(expected, output)
- end
-
+ end
def test_run_failing_filtered
tc = Class.new(MiniTest::Unit::TestCase) do
def test_something
@@ -426,7 +428,7 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_includes_triggered
- @assertion_count = 4
+ @assertion_count = 3
e = @tc.assert_raises MiniTest::Assertion do
@tc.assert_includes [true], false
@@ -489,31 +491,35 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_raises
- @assertion_count = 2
-
@tc.assert_raises RuntimeError do
raise "blah"
end
end
- def test_assert_raises_triggered_different
- @assertion_count = 2
+ def test_assert_raises_module
+ @tc.assert_raises M do
+ raise E
+ end
+ end
+ def test_assert_raises_triggered_different
e = assert_raises MiniTest::Assertion do
@tc.assert_raises RuntimeError do
raise SyntaxError, "icky"
end
end
- expected = "<[RuntimeError]> exception expected, not
+ expected = "[RuntimeError] exception expected, not
Class: <SyntaxError>
Message: <\"icky\">
---Backtrace---
FILE:LINE:in `test_assert_raises_triggered_different'
----------------.
-Expected [RuntimeError] to include SyntaxError."
+---------------"
- assert_equal expected, expected.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
+ actual = e.message.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
+ actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/
+
+ assert_equal expected, actual
end
def test_assert_raises_triggered_none
@@ -528,6 +534,26 @@ Expected [RuntimeError] to include SyntaxError."
assert_equal expected, e.message
end
+ def test_assert_raises_triggered_subclass
+ e = assert_raises MiniTest::Assertion do
+ @tc.assert_raises StandardError do
+ raise E
+ end
+ end
+
+ expected = "[StandardError] exception expected, not
+Class: <E>
+Message: <\"E\">
+---Backtrace---
+FILE:LINE:in `test_assert_raises_triggered_subclass'
+---------------"
+
+ actual = e.message.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
+ actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/
+
+ assert_equal expected, actual
+ end
+
def test_assert_respond_to
@tc.assert_respond_to "blah", :empty?
end
@@ -733,7 +759,7 @@ Expected [RuntimeError] to include SyntaxError."
end
def test_refute_includes_triggered
- @assertion_count = 4
+ @assertion_count = 3
e = @tc.assert_raises MiniTest::Assertion do
@tc.refute_includes [true], true