JRuby 和 Test::Unit 的assert_raise
我无法让 assert_raise
识别 java 异常。
我可以做得
assert_raise(NativeException) { @iter.next }
很好,但如果我尝试更具体,
java_import 'java.util.NoSuchElementException'
#...
assert_raise(NoSuchElementException) { @iter.next }
我会收到错误
Should expect a class of exception, Java::JavaUtil::NoSuchElementException.
<nil> is not true.
但是,我可以使用 begin/rescue/end
来捕获异常:
assert(begin
@iter.next
false
rescue NoSuchElementException
true
end)
我做错了什么吗?或者这是 Test::Unit
方面的失败?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会把它作为一个错误提出。当它在块中引发时,它似乎无法理解 java 类,因为它返回 nil,因此测试失败。
我在 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] 下运行它
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]