MiniTest Assertions Cheat Sheet

A Programming › Ruby cheat sheet in English by CITguy
21,426 views 4,170 downloads 11 Sep 2013 History
3.7 avg · 0 ratings

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

Badges

Useful Cheat Sheet Nice Cheat Sheet Good Cheat Sheet Downloaded from Unusual Locations × 1

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.