Show Menu

MiniTest Assertions Cheat Sheet by

MiniTest Generic Assertions

assert( test, msg=nil )
assert­_equal( obj, val, msg=nil )
assert­_in­sta­nce_of( klass, obj, msg=nil )
assert­_ki­nd_of( klass, obj, msg=nil )
assert­_match( regex, obj, msg=nil )
assert_nil( obj, msg=nil )
assert­_op­erator( obj, operator, val, msg=nil )
assert­_re­spo­nd_to( obj, method, msg=nil )
assert­_same( obj, obj2, msg=nil )

MiniTest Block Assertions

assert­_block( msg=nil ) do ... end
assert­_output( stdout=nil, stderr=nil ) do ... end
assert­_raises( exception ) do ... end
assert­_silent do ... end
assert­_throws( sym, msg=nil )

MiniTest Enumerable Assertions

assert­_empty( obj, msg=nil )
assert­_in­cludes( collection, obj, msg=nil )

MiniTest Float Assertions

assert­_in­_delta(val, obj, delta=­0.001, msg=nil)
assert­_in­_ep­silon(val, obj, e=0.001, msg=nil)

MiniTe­st:­:Spec Enumerable Expect­ations

obj.(must|­won­t)_­include( obj2 )

MiniTe­st:­:Spec Float Expect­ations

obj.(must|­won­t)_­be_­clo­se_to( val, [delta] )
equivalent to assert­_in­_delta
obj.(must|­won­t)_­be_­wit­hin­_delta( val, [delta] )
Fails unless obj and val are within delta of each other
obj.(must|­won­t)_­be_­wit­hin­_ep­silon(val, [e])
Fails unless obj and val have a relative error less than e

MiniTe­st:­:Spec Generic Expect­ations

obj.(must|­won­t)_be( operator, expected )
10.must_be :<, 11
obj.(must|­won­t)_­be_­ins­tan­ce_of( klass )
obj.(must|­won­t)_­be_­kind_of( klass )
obj.(must|­won­t)_­be_­same_as( obj2 )
obj.(must|­won­t)_­equal( obj2 )
obj.(must|­won­t)_­match( regex )
obj.(must|­won­t)_­res­pond_to( message )

MiniTe­st:­:Spec Block Expect­ations

->{ }.must_b­e_s­ilent()
Fails if block outputs anything to stderr or stdout.
->{ }.must_o­utput( stdout, [stderr] )
The block should have certain output on stdout or stderr. Set stdout to nil just to check stderr.
->{ }.must_raise( exception )
Fails unless block raises exception
->{ }.must_throw( sym )
Fails unless block throws sym
Works on procs, blocks, and lambdas


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

            Ruby on Rails Cheat Sheet by Dave Child and
          ISTQB Test Automation Engineering Cheat Sheet
 Cheat Sheet

          More Cheat Sheets by CITguy

          jasmine JS testing Cheat Sheet
          Extending Ruby with C - Part 1 Cheat Sheet
          *nix users and groups Cheat Sheet