Ruby on Rails 7 ships with Minitest. Here's a definitive guide to what assertions are available in Minitest 5.1.
| Assertion | Asserts | 
|---|---|
| assert( test, [msg] ) | Asserts that testis true. | 
| assert_not( test, [msg] ) | Asserts that testis false. | 
| assert_equal( expected, actual, [msg] ) | Asserts that expected == actualis true. | 
| assert_not_equal( expected, actual, [msg] ) | Asserts that expected != actualis true. | 
| assert_same( expected, actual, [msg] ) | Asserts that expected.equal?(actual)is true. | 
| assert_not_same( expected, actual, [msg] ) | Asserts that expected.equal?(actual)is false. | 
| assert_nil( obj, [msg] ) | Asserts that obj.nil?is true. | 
| assert_not_nil( obj, [msg] ) | Asserts that obj.nil?is false. | 
| assert_empty( obj, [msg] ) | Asserts that objisempty?. | 
| assert_not_empty( obj, [msg] ) | Asserts that objis notempty?. | 
| assert_match( regexp, string, [msg] ) | Asserts that a string matches the regular expression. | 
| assert_no_match( regexp, string, [msg] ) | Asserts that a string doesn't match the regular expression. | 
| assert_includes( collection, obj, [msg] ) | Asserts that objis incollection. | 
| assert_not_includes( collection, obj, [msg] ) | Asserts that objis not incollection. | 
| assert_in_delta( expected, actual, [delta], [msg] ) | Asserts that the numbers expectedandactualare withindeltaof each other. | 
| assert_not_in_delta( expected, actual, [delta], [msg] ) | Asserts that the numbers expectedandactualare not withindeltaof each other. | 
| assert_in_epsilon ( expected, actual, [epsilon], [msg] ) | Asserts that the numbers expectedandactualhave a relative error less thanepsilon. | 
| assert_not_in_epsilon ( expected, actual, [epsilon], [msg] ) | Asserts that the numbers expectedandactualhave a relative error not less thanepsilon. | 
| assert_throws( symbol, [msg] ) { block } | Asserts that the given block throws the symbol. | 
| assert_raises( exception1, exception2, ... ) { block } | Asserts that the given block raises one of the given exceptions. | 
| assert_instance_of( class, obj, [msg] ) | Asserts that objis an instance ofclass. | 
| assert_not_instance_of( class, obj, [msg] ) | Asserts that objis not an instance ofclass. | 
| assert_kind_of( class, obj, [msg] ) | Asserts that objis an instance ofclassor is descending from it. | 
| assert_not_kind_of( class, obj, [msg] ) | Asserts that objis not an instance ofclassand is not descending from it. | 
| assert_respond_to( obj, symbol, [msg] ) | Asserts that objresponds tosymbol. | 
| assert_not_respond_to( obj, symbol, [msg] ) | Asserts that objdoes not respond tosymbol. | 
| assert_operator( obj1, operator, [obj2], [msg] ) | Asserts that obj1.operator(obj2)is true. | 
| assert_not_operator( obj1, operator, [obj2], [msg] ) | Asserts that obj1.operator(obj2)is false. | 
| assert_predicate ( obj, predicate, [msg] ) | Asserts that obj.predicateis true, e.g.assert_predicate str, :empty? | 
| assert_not_predicate ( obj, predicate, [msg] ) | Asserts that obj.predicateis false, e.g.assert_not_predicate str, :empty? | 
| assert_error_reported(class) { block } | Asserts that the error class has been reported, e.g. assert_error_reported IOError { Rails.error.report(IOError.new("Oops")) } | 
| assert_no_error_reported { block } | Asserts that no errors have been reported, e.g. assert_no_error_reported { perform_service } | 
| flunk( [msg] ) | Asserts failure. This is useful to explicitly mark a test that isn't finished yet. | 
We're writing Ruby on Rails at Salvation Co. Technologists keen on Saving The World are invited to join the innovations. Salvation Company
 

 
    
Top comments (0)