assert_raise fails on native exceptions ---------------------------------------
Key: JRUBY-5279 URL: http://jira.codehaus.org/browse/JRUBY-5279 Project: JRuby Issue Type: Bug Affects Versions: JRuby 1.5.6 Reporter: Jeff Hodges Assignee: Thomas E Enebo assert_raise in test/unit does not properly handle NativeExceptions. When given one to test against, the code in _check_exception_class checks if the class inherits from the ruby Exception class (with `assert(Exception >= klass,...`). This fails when a NativeException is passed into it. A similar bug was made earlier as JTESTR-45, but the reporter focused on rspec (which was found to be invalid) and did not follow through with test/unit and the bug was not elevated to JRUBY. Also, this seems to have been known on the web at [http://stackoverflow.com/questions/2187166/jruby-and-testunits-assert-raise] with no resolution. This code reproduces the problem: {code} require 'test/unit' require 'java' class TestAssertRaiseWithNativeException < Test::Unit::TestCase java_import('java.util.NoSuchElementException') { 'FooError' } java_import 'java.util.MissingResourceException' def test_native_exception_with_renaming assert_raise(FooError) { raise FooError } end def test_native_exception assert_raise(Java::JavaUtil::MissingResourceException) { raise Java::JavaUtil::MissingResourceException } end end {code} The above tests will fail with these results: {code} 1) Failure: test_native_exception(TestAssertRaiseAliasedNativeException) [assert_raise_problem.rb:15]: Should expect a class of exception, Java::JavaUtil::MissingResourceException. <nil> is not true. 2) Failure: test_native_exception_with_renaming(TestAssertRaiseAliasedNativeException) [assert_raise_problem.rb:8]: Should expect a class of exception, Java::JavaUtil::NoSuchElementException. <nil> is not true. {code} -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email