Minitest is the default testing library used by Ruby on Rails. Here's a synopsis of the available api.
Available Assertions
From Minitest:
| Assertion | Purpose | 
|---|---|
| assert( test, [msg] ) | Ensures that testis true. | 
| assert_not( test, [msg] ) | Ensures that testis false. | 
| assert_equal( expected, actual, [msg] ) | Ensures that expected == actualis true. | 
| assert_not_equal( expected, actual, [msg] ) | Ensures that expected != actualis true. | 
| assert_same( expected, actual, [msg] ) | Ensures that expected.equal?(actual)is true. | 
| assert_not_same( expected, actual, [msg] ) | Ensures that expected.equal?(actual)is false. | 
| assert_nil( obj, [msg] ) | Ensures that obj.nil?is true. | 
| assert_not_nil( obj, [msg] ) | Ensures that obj.nil?is false. | 
| assert_empty( obj, [msg] ) | Ensures that objisempty?. | 
| assert_not_empty( obj, [msg] ) | Ensures that objis notempty?. | 
| assert_match( regexp, string, [msg] ) | Ensures that a string matches the regular expression. | 
| assert_no_match( regexp, string, [msg] ) | Ensures that a string doesn't match the regular expression. | 
| assert_includes( collection, obj, [msg] ) | Ensures that objis incollection. | 
| assert_not_includes( collection, obj, [msg] ) | Ensures that objis not incollection. | 
| assert_in_delta( expected, actual, [delta], [msg] ) | Ensures that the numbers expectedandactualare withindeltaof each other. | 
| assert_not_in_delta( expected, actual, [delta], [msg] ) | Ensures that the numbers expectedandactualare not withindeltaof each other. | 
| assert_in_epsilon ( expected, actual, [epsilon], [msg] ) | Ensures that the numbers expectedandactualhave a relative error less thanepsilon. | 
| assert_not_in_epsilon ( expected, actual, [epsilon], [msg] ) | Ensures that the numbers expectedandactualhave a relative error not less thanepsilon. | 
| assert_throws( symbol, [msg] ) { block } | Ensures that the given block throws the symbol. | 
| assert_raises( exception1, exception2, ... ) { block } | Ensures that the given block raises one of the given exceptions. | 
| assert_instance_of( class, obj, [msg] ) | Ensures that objis an instance ofclass. | 
| assert_not_instance_of( class, obj, [msg] ) | Ensures that objis not an instance ofclass. | 
| assert_kind_of( class, obj, [msg] ) | Ensures that objis an instance ofclassor is descending from it. | 
| assert_not_kind_of( class, obj, [msg] ) | Ensures that objis not an instance ofclassand is not descending from it. | 
| assert_respond_to( obj, symbol, [msg] ) | Ensures that objresponds tosymbol. | 
| assert_not_respond_to( obj, symbol, [msg] ) | Ensures that objdoes not respond tosymbol. | 
| assert_operator( obj1, operator, [obj2], [msg] ) | Ensures that obj1.operator(obj2)is true. | 
| assert_not_operator( obj1, operator, [obj2], [msg] ) | Ensures that obj1.operator(obj2)is false. | 
| assert_predicate ( obj, predicate, [msg] ) | Ensures that obj.predicateis true, e.g.assert_predicate str, :empty? | 
| assert_not_predicate ( obj, predicate, [msg] ) | Ensures that obj.predicateis false, e.g.assert_not_predicate str, :empty? | 
| assert_error_reported(class) { block } | Ensures that the error class has been reported, e.g. assert_error_reported IOError { Rails.error.report(IOError.new("Oops")) } | 
| assert_no_error_reported { block } | Ensures that no errors have been reported, e.g. assert_no_error_reported { perform_service } | 
| flunk( [msg] ) | Ensures failure. This is useful to explicitly mark a test that isn't finished yet. | 
From Rails:
| Assertion | Purpose | 
|---|---|
| assert_difference(expressions, difference = 1, message = nil) {...} | Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. | 
| assert_no_difference(expressions, message = nil, &block) | Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block. | 
| assert_changes(expressions, message = nil, from:, to:, &block) | Test that the result of evaluating an expression is changed after invoking the passed in block. | 
| assert_no_changes(expressions, message = nil, &block) | Test the result of evaluating an expression is not changed after invoking the passed in block. | 
| assert_nothing_raised { block } | Ensures that the given block doesn't raise any exceptions. | 
| assert_recognizes(expected_options, path, extras={}, message=nil) | Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options. | 
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) | Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures. | 
| assert_response(type, message = nil) | Asserts that the response comes with a specific status code. You can specify :successto indicate 200-299,:redirectto indicate 300-399,:missingto indicate 404, or:errorto match the 500-599 range. You can also pass an explicit status number or its symbolic equivalent. For more information, see full list of status codes and how their mapping works. | 
| assert_redirected_to(options = {}, message=nil) | Asserts that the response is a redirect to a URL matching the given options. You can also pass named routes such as assert_redirected_to root_pathand Active Record objects such asassert_redirected_to @article. | 
| assert_queries_count(count = nil, include_schema: false, &block) | Asserts that &blockgenerates anintnumber of SQL queries. | 
| assert_no_queries(include_schema: false, &block) | Asserts that &blockgenerates no SQL queries. | 
| assert_queries_match(pattern, count: nil, include_schema: false, &block) | Asserts that &blockgenerates SQL queries that match the pattern. | 
| assert_no_queries_match(pattern, &block) | Asserts that &blockgenerates no SQL queries that match the pattern. | 
Here's that thing you need. I got it from guides.rubyonrails.org/testing.html.
 

 
    
Top comments (0)