I’m having trouble making assert_raise recognize java exceptions.
I can do
assert_raise(NativeException) { @iter.next }
which works fine, but if I try to get more specific
java_import 'java.util.NoSuchElementException'
#...
assert_raise(NoSuchElementException) { @iter.next }
I get the error
Should expect a class of exception, Java::JavaUtil::NoSuchElementException.
<nil> is not true.
However, I can use begin/rescue/end to catch the exception:
assert(begin
@iter.next
false
rescue NoSuchElementException
true
end)
Is there something I’m doing wrong, or is this a failure on Test::Unit‘s part?
I would raise it as a bug. It seems it cannot understand the java class when it raised in a block, since it returns nil and therefore, fails the test.
I ran it under jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) Client VM 1.5.0_22) [i386-java]