我正在尝试编写这样的代码:
assert_throws(:ExtractionFailed) { unit.extract_from('5 x 2005')}
ExtractionFailed
是一个微不足道的子类Exception
,并且在测试/单元下,我试图断言它在我调用 unit.extract_from(... bad data...) 时被抛出
我已经ExtractionFailed
进入 SemanticText 模块,所以现在 test/unit 说:
<:ExtractionFailed> expected to be thrown but
<:"SemanticText::ExtractionFailed"> was thrown.
我试着写 assert_throws(:SemanticText::ExtractionFailed) {...} 但我得到了相当混乱的消息:TypeError: SemanticText is not a class/module
我可以通过执行以下操作使其工作(虽然它看起来像一个 hack):
assert_throws(SemanticText::ExtractionFailed.to_s.to_sym) { unit.extract_from('5 x 2005')}
那么在 ruby 中表达这个断言的正确方式是什么?