Fixed assert_in_delta (should be >=, not >). Fixed assert_raises to match Modules. Fixed capture_io to not dup IOs. Fixed skip's backtrace.

[git-p4: depot-paths = "//src/minitest/dev/": change = 4428]
This commit is contained in:
Ryan Davis 2008-10-25 14:13:39 -08:00
parent d79ec6d12c
commit 7b882ebc6b
5 changed files with 68 additions and 34 deletions

View File

@ -10,6 +10,6 @@ Autotest.add_hook :initialize do |at|
at.add_exception 'coverage'
end
require 'autotest/rcov'
Autotest::RCov.command = 'rcov_info'
# require 'autotest/rcov'
# Autotest::RCov.command = 'rcov_info'

View File

@ -1,3 +1,13 @@
=== 1.3.1 / 2008-10-25
* 4 bug fixes:
* Fixed assert_in_delta (should be >=, not >).
* Fixed assert_raises to match Modules.
* Fixed capture_io to not dup IOs.
* Fixed skip's backtrace.
=== 1.3.0 / 2008-10-09
* 2 major enhancements:

View File

@ -81,7 +81,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
@ -133,7 +133,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
@ -182,12 +185,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
@ -297,14 +300,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

View File

@ -4,7 +4,7 @@ MiniTest::Unit.autorun
describe MiniTest::Spec do
before do
@assertion_count = 5
@assertion_count = 4
end
after do
@ -59,7 +59,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
@ -67,7 +67,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
@ -83,14 +84,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)
@ -98,13 +99,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
@ -120,7 +121,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

View File

@ -3,8 +3,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
@ -242,10 +244,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
@ -420,7 +422,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
@ -483,31 +485,32 @@ 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')
assert_equal expected, e.message.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
end
def test_assert_raises_triggered_none
@ -522,6 +525,23 @@ 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'
---------------"
assert_equal expected, e.message.gsub(/[\w\/\.]+:\d+/, 'FILE:LINE')
end
def test_assert_respond_to
@tc.assert_respond_to "blah", :empty?
end
@ -727,7 +747,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