Skip to content

Commit

Permalink
+ Errors in teardown are now recorded. (randycoulman)
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 8111]
  • Loading branch information
zenspider committed Jan 15, 2013
1 parent 86c3ce2 commit c4a4d92
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions .autotest
Expand Up @@ -10,6 +10,7 @@ Autotest.add_hook :initialize do |at|
at.extra_class_map["TestMeta"] = "test/test_minitest_spec.rb"
at.extra_class_map["TestMiniTestUnitTestCase"] = "test/test_minitest_unit.rb"
at.extra_class_map["TestMiniTestUnit"] = "test/test_minitest_unit.rb"
at.extra_class_map["TestMiniTestUnitRecording"]= "test/test_minitest_unit.rb"
at.extra_class_map["TestMiniTestStub"] = "test/test_minitest_mock.rb"
at.add_exception 'coverage.info'
at.add_exception 'coverage'
Expand Down
1 change: 1 addition & 0 deletions lib/minitest/unit.rb
Expand Up @@ -1315,6 +1315,7 @@ def run runner
raise
rescue Exception => e
@passed = false
runner.record self.class, self.__name__, self._assertions, time, e
result = runner.puke self.class, self.__name__, e
end
end
Expand Down
82 changes: 82 additions & 0 deletions test/minitest/test_minitest_unit.rb
Expand Up @@ -1742,3 +1742,85 @@ def test_windows_eh
assert self.windows? "mswin"
end
end

class TestMiniTestUnitRecording < MetaMetaMetaTestCase
# do not parallelize this suite... it just can't handle it.

def assert_run_record(*expected, &block)
def @tu.record suite, method, assertions, time, error
recording[method] << error
end

def @tu.recording
@recording ||= Hash.new { |h,k| h[k] = [] }
end

MiniTest::Unit.runner = @tu

Class.new MiniTest::Unit::TestCase, &block

with_output do
@tu.run
end

recorded = @tu.recording.fetch("test_method").map(&:class)

assert_equal expected, recorded
end

def test_record_passing
assert_run_record NilClass do
def test_method
assert true
end
end
end

def test_record_failing
assert_run_record MiniTest::Assertion do
def test_method
assert false
end
end
end

def test_record_error
assert_run_record RuntimeError do
def test_method
raise "unhandled exception"
end
end
end

def test_record_error_teardown
assert_run_record NilClass, RuntimeError do
def test_method
assert true
end

def teardown
raise "unhandled exception"
end
end
end

def test_record_error_in_test_and_teardown
assert_run_record AnError, RuntimeError do
def test_method
raise AnError
end

def teardown
raise "unhandled exception"
end
end
end

def test_record_skip
assert_run_record MiniTest::Skip do
def test_method
skip "not yet"
end
end
end
end

0 comments on commit c4a4d92

Please sign in to comment.