Show Menu

MiniTest Assertions Cheat Sheet by

test     spec     ruby     minitest-spec

MiniTest Generic Assertions

asse­rt( test, msg=nil )
invers­e:­re­fute
asse­rt_­equ­al( obj, val, msg=nil )
invers­e:­re­fut­e_e­qual
asse­rt_­ins­tan­ce_­of( klass, obj, msg=nil )
invers­e:­re­fut­e_i­nst­anc­e_of
asse­rt_­kin­d_of( klass, obj, msg=nil )
invers­e:­re­fut­e_k­ind­_of
asse­rt_­mat­ch( regex, obj, msg=nil )
invers­e:­re­fut­e_m­atch
asse­rt_­nil( obj, msg=nil )
invers­e:­re­fut­e_nil
asse­rt_­ope­rat­or( obj, opera­tor, val, msg=nil )
invers­e:­re­fut­e_o­per­ator
asse­rt_­res­pon­d_to( obj, method, msg=nil )
invers­e:­re­fut­e_r­esp­ond­_to
asse­rt_­same( obj, obj2, msg=nil )
invers­e:­re­fut­e_s­ame

MiniTest Block Assertions

asse­rt_­blo­ck( msg=nil ) do ... end
asse­rt_­out­put( stdou­t=nil, stder­r=nil ) do ... end
asse­rt_­rai­ses( excep­tion ) do ... end
asse­rt_­sil­ent do ... end
asse­rt_­thr­ows( sym, msg=nil )
 

MiniTest Enumerable Assertions

asse­rt_­emp­ty( obj, msg=nil )
asse­rt_­inc­lud­es( colle­ction, obj, msg=nil )

MiniTest Float Assertions

asse­rt_­in_­del­ta­(­val, obj, delta­=0.0­01, msg=nil)
asse­rt_­in_­eps­ilo­n­(val, obj, e=0.001, msg=nil)

MiniTe­st:­:Spec Enumerable Expect­ations

obj.­(­mus­t|w­ont­)_b­e_e­mpt­y()
obj.­(­mus­t|w­ont­)_i­ncl­ude( obj2 )

MiniTe­st:­:Spec Float Expect­ations

obj.­(­mus­t|w­ont­)_b­e_c­los­e_to( val, [delta] )
equivalent to asser­t_i­n_d­elta
obj.­(­mus­t|w­ont­)_b­e_w­ith­in_­del­ta( val, [delta] )
Fails unless obj and val are within delta of each other
obj.­(­mus­t|w­ont­)_b­e_w­ith­in_­eps­ilo­n­(val, [e])
Fails unless obj and val have a relative error less than e
 

MiniTe­st:­:Spec Generic Expect­ations

obj.­(­mus­t|w­ont­)_be( opera­tor, expected )
10.mu­st_be :<, 11
obj.­(­mus­t|w­ont­)_b­e_i­nst­anc­e_of( klass )
obj.­(­mus­t|w­ont­)_b­e_k­ind­_of( klass )
obj.­(­mus­t|w­ont­)_b­e_n­il()
obj.­(­mus­t|w­ont­)_b­e_s­ame­_as( obj2 )
obj.­(­mus­t|w­ont­)_e­qual( obj2 )
obj.­(­mus­t|w­ont­)_m­atch( regex )
obj.­(­mus­t|w­ont­)_r­esp­ond­_to( message )

MiniTe­st:­:Spec Block Expect­ations

->{ }.m­ust­_be­_si­len­t()
Fails if block outputs anything to stderr or stdout.
->{ }.m­ust­_ou­tput( stdout, [stderr] )
The block should have certain output on stdout or stderr. Set stdout to nil just to check stderr.
->{ }.m­ust­_ra­ise( excep­tion )
Fails unless block raises excep­tion
->{ }.m­ust­_th­row( sym )
Fails unless block throws sym
Works on procs, bloc­ks, and lamb­das

Download the MiniTest Assertions Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/citguy_minitest-assertions.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

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

          Rails 4 Cheat Sheet
            Ruby on Rails Cheat Sheet by Dave Child and addedbytes.com

          More Cheat Sheets by CITguy

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