Ruby’s Test::Unit has assert_nothing_raised. Test::Unit has been replaced by MiniTest. Why don’t MiniTest’s assertions / expectations have anything parallel to this? For example you can expect must_raise but not wont_raise.
Ruby’s Test::Unit has assert_nothing_raised . Test::Unit has been replaced by MiniTest . Why don’t
Share
MiniTest does implement
assert_nothing_raisedin its Test::Unit compatibility layer, but in its own tests (MiniTest::UnitandMiniTest::Spec) it does not implement any test like this. The reason is, the programmer argues, that testing for nothing raised is not a test of anything; you never expect anything to be raised in a test, except when you are testing for an exception. If an unexpected (uncaught) exception occurs in the code for a test, you’ll get an exception reported in good order by the test and you’ll know you have a problem.Example:
Output:
Which is exactly what you wanted to know. If you were expecting nothing to be raised, you didn’t get it and you’ve been told so.
So, the argument here is: do not use
assert_nothing_raised! It’s just a meaningless crutch. See, for example:https://github.com/seattlerb/minitest/issues/70
https://github.com/seattlerb/minitest/issues/159
http://blog.zenspider.com/blog/2012/01/assert_nothing_tested.html
On the other hand, clearly
assert_nothing_raisedcorresponds to some intuition among users, since so many people expect awont_raiseto go withmust_raise, etc. In particular one would like to focus an assertion on this, not merely a test. Luckily, MiniTest is extremely minimalist and flexible, so if you want to add your own routine, you can. So you can write a method that tests for no exception and returns a known outcome if there is no exception, and now you can assert for that known outcome.For example (I’m not saying this is perfect, just showing the idea):
The point is not that this is a good or bad idea but that it was never the responsibility of MiniTest to do it for you.