Minitest and Minitest/Spec
Handy tipsheet for writing unit tests in Ruby

Content Credit: Minitest Cheatsheet

test


capture_io
flunk msg = nil
pass  msg = nil
skip  msg = nil, bt = caller

assert             test, msg = nil
assert_block       msg = nil
assert_empty       obj, msg = nil
assert_equal       exp, act, msg = nil
assert_in_delta    exp, act, delta = 0.001, msg = nil
assert_in_epsilon  a, b, epsilon = 0.001, msg = nil
assert_includes    collection, obj, msg = nil
assert_instance_of cls, obj, msg = nil
assert_kind_of     cls, obj, msg = nil
assert_match       exp, act, msg = nil
assert_nil         obj, msg = nil
assert_operator    o1, op, o2, msg = nil
assert_output      stdout = nil, stderr = nil
assert_raises      *exp
assert_respond_to  obj, meth, msg = nil
assert_same        exp, act, msg = nil
assert_send        send_ary, m = nil
assert_silent
assert_throws      sym, msg = nil

refute             test, msg = nil
refute_empty       obj, msg = nil
refute_equal       exp, act, msg = nil
refute_in_delta    exp, act, delta = 0.001, msg = nil
refute_in_epsilon  a, b, epsilon = 0.001, msg = nil
refute_includes    collection, obj, msg = nil
refute_instance_of cls, obj, msg = nil
refute_kind_of     cls, obj, msg = nil
refute_match       exp, act, msg = nil
refute_nil         obj, msg = nil
refute_operator    o1, op, o2, msg = nil
refute_respond_to  obj, meth, msg = nil
refute_same        exp, act, msg = nil

spec

 1
 2must_be                -> assert_operator
 3must_be_close_to       -> assert_in_delta
 4must_be_empty          -> assert_empty
 5must_be_instance_of    -> assert_instance_of
 6must_be_kind_of        -> assert_kind_of
 7must_be_nil            -> assert_nil
 8must_be_same_as        -> assert_same
 9must_be_silent         -> assert_silent
10must_be_within_delta   -> assert_in_delta
11must_be_within_epsilon -> assert_in_epsilon
12must_equal             -> assert_equal
13must_include           -> assert_includes
14must_match             -> assert_match
15must_output            -> assert_output
16must_raise             -> assert_raises
17must_respond_to        -> assert_respond_to
18must_send              -> assert_send
19must_throw             -> assert_throws
20
21wont_be                -> refute_operator
22wont_be_close_to       -> refute_in_delta
23wont_be_empty          -> refute_empty
24wont_be_instance_of    -> refute_instance_of
25wont_be_kind_of        -> refute_kind_of
26wont_be_nil            -> refute_nil
27wont_be_same_as        -> refute_same
28wont_be_within_delta   -> refute_in_delta
29wont_be_within_epsilon -> refute_in_epsilon
30wont_equal             -> refute_equal
31wont_include           -> refute_includes
32wont_match             -> refute_match
33wont_respond_to        -> refute_respond_to

mock

expect(name, retval, args=\[\])
verify