In the previous essay, we tested Login_controller, and we used a lot of rails built in assertions and get,put to test it. Take a look at some of the rails ' conventions on functional testing this time.
1.HTTP requested methods (HTTP request method)
The following methods are used to simulate HTTP requests and receive a response (response)
Get () the put ()
post () The
Delete (
) head ()
Each of these five functions has the same four parameters, with get () as an example:
Get (action, parameters = nil, session = nil, Flash = nil)
Sends an HTTP GET request to the specified action and sets the response, with four parameters meaning:
An action for a controller (controller) specified by the Action:http request.
Parameters: Optional hash, as a parameter to the request.
Session: Optional, session hash.
Flash: optional, flash hash.
Here is an example:
Get:index
Get:add_to_cart,: ID => @version_control_book. ID
get:add_to_cart,: ID => @version_control_ Book.id,
: Session_key => ' Session_value ',: Message => "success!"