Show Menu
Cheatography

MiniTest Assertions Cheat Sheet by

MiniTest Generic Assertions

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

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)_­be_­empty()
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_nil()
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
           
 

Comments

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 addedbytes.com
          ISTQB Test Automation Engineering Cheat Sheet
          Cypress.io 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