method
assert
v1_9_2_180 -
Show latest stable
- Class:
Test::Unit::Assertions
assert(test, msg = (nomsg = true; nil))public
No documentation available.
# File lib/test/unit/assertions.rb, line 13
def assert(test, msg = (nomsg = true; nil))
unless nomsg or msg.instance_of?(String) or msg.instance_of?(Proc) or
(bt = caller).first.rindex(MiniTest::MINI_DIR, 0)
bt.delete_if {|s| s.rindex(MiniTest::MINI_DIR, 0)}
raise ArgumentError, "assertion message must be String or Proc, but #{msg.class} was given.", bt
end
super
end 1Note
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.