assert
- 1_8_6_287 (0)
- 1_8_7_72 (0)
- 1_8_7_330 (0)
- 1_9_1_378
- 1_9_2_180 (-11)
- 1_9_3_125 (38)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9
- 2_4_6
- 2_5_5
- 2_6_3
- What's this?
assert(test, msg = UNASSIGNED)
public
Tests if test is true.
msg may be a String or a Proc. If msg is a String, it will be used as the failure message. Otherwise, the result of calling msg will be used as the message if the assertion fails.
If no msg is given, a default message will be used.
assert(false, "This was expected to be true")
Use message param
The message param is invaluable in case test fails – if you use it to display relevant info, you will find out what went wrong much faster.
Reworking the silly example above:
assert some_list.include?(5)
will only tell you that
<false> is not true.
which isn’t terribly helpful, is it? But if you use message like that:
assert some_list.include?(5), "some_list = #{some_list.inspect}"
the output will be:
some_list = [1, 2]. <false> is not true.
which in most cases should give you strong hints as to why the test failed.