私は次のようなコードを書こうとしています:
assert_throws(:ExtractionFailed) { unit.extract_from('5 x 2005')}
ExtractionFailed
の自明なサブクラスでありException
、テスト/ユニットの下で、 unit.extract_from(... bad data...) を呼び出すとスローされることをアサートしようとしています
SemanticText モジュールに移動ExtractionFailed
したので、test/unit は次のようになります。
<:ExtractionFailed> expected to be thrown but
<:"SemanticText::ExtractionFailed"> was thrown.
assert_throws(:SemanticText::ExtractionFailed) {...} を書いてみましたが、かなり紛らわしいメッセージが表示されました。TypeError: SemanticText is not a class/module
次のようにすることで機能させることができます(ハックのように見えますが):
assert_throws(SemanticText::ExtractionFailed.to_s.to_sym) { unit.extract_from('5 x 2005')}
では、このアサーションを Ruby で表現する正しい方法は何でしょうか?