What is the expected syntax for checking exception messages in MiniTest's assert_raises/must_raise?

后端 未结 4 1253
粉色の甜心
粉色の甜心 2020-12-25 09:39

What is the expected syntax for checking exception messages in MiniTest\'s assert_raises/must_raise?

I\'m trying to make an assertion somet

4条回答
  •  旧巷少年郎
    2020-12-25 09:53

    To assert exception:

    assert_raises FooError do
      bar.do_it
    end
    

    To assert exception message:

    As per API doc, assert_raises returns the exception matched so you can check the message, attributes, etc.

    exception = assert_raises FooError do
      bar.do_it
    end
    assert_equal('Foo', exception.message)
    

提交回复
热议问题