class

Marten::Spec::Client

Inherits Reference / Object

A test client allowing to issue requests to the server and obtain the associated responses.

By leveraging this test client, developers can easily forge various requests and obtain the corresponding responses returned by the server. In the process, the test client ensures that all the configured middlewares are used and applied.

It should be noted that a test client is stateful: cookies and session data will be retained for the lifetime of a specific client instance.

Moreover, the test client disables CSRF checks by default in order to ease the process of testing unsafe request methods. If you trully need to have these checks applied when running specs, you can initialize a test client by setting disable_request_forgery_protection to false.

Constructors

new(content_type : String | Nil = nil, disable_request_forgery_protection : Bool = true)
Source

Instance methods

cookies

Returns a Marten::HTTP::Cookies object that can be leveraged to set cookies that should be used by the client.

Cookies that are defined via this hash-like object will automatically be used for every request issued by the test client.

Source
delete(path : String, data : Hash | NamedTuple | Nil | String = nil, query_params : Hash | NamedTuple | Nil = nil, content_type : String | Nil = nil, headers : Hash | NamedTuple | Nil = nil, secure = false) : Marten::HTTP::Response

Allows to issue a DELETE request to the server.

Source
get(path : String, query_params : Hash | NamedTuple | Nil = nil, content_type : String | Nil = nil, headers : Hash | NamedTuple | Nil = nil, secure = false) : Marten::HTTP::Response

Allows to issue a GET request to the server.

Source
head(path : String, query_params : Hash | NamedTuple | Nil = nil, content_type : String | Nil = nil, headers : Hash | NamedTuple | Nil = nil, secure = false)

Allows to issue a HEAD request to the server.

Source
headers

Returns a Marten::HTTP::Headers object that can be leveraged to set headers that should bet for each request.

Source
options(path : String, query_params : Hash | NamedTuple | Nil = nil, content_type : String | Nil = nil, headers : Hash | NamedTuple | Nil = nil, secure = false)

Allows to issue an OPTIONS request to the server.

Source
patch(path : String, data : Hash | NamedTuple | Nil | String = nil, query_params : Hash | NamedTuple | Nil = nil, content_type : String | Nil = nil, headers : Hash | NamedTuple | Nil = nil, secure = false) : Marten::HTTP::Response

Allows to issue a PATCH request to the server.

Source
post(path : String, data : Hash | NamedTuple | Nil | String = nil, query_params : Hash | NamedTuple | Nil = nil, content_type : String | Nil = nil, headers : Hash | NamedTuple | Nil = nil, secure = false) : Marten::HTTP::Response

Allows to issue a POST request to the server.

Source
put(path : String, data : Hash | NamedTuple | Nil | String = nil, query_params : Hash | NamedTuple | Nil = nil, content_type : String | Nil = nil, headers : Hash | NamedTuple | Nil = nil, secure = false) : Marten::HTTP::Response

Allows to issue a PUT request to the server.

Source
session

Returns a session store object for the client.

This method returns a session store object, initialized using the currently configured session store. The test client will ensure that this session store is automatically saved and that the session key is persisted in the cookies before issuing requests.

Source
trace(path : String, data : Hash | NamedTuple | Nil | String = nil, query_params : Hash | NamedTuple | Nil = nil, content_type : String | Nil = nil, headers : Hash | NamedTuple | Nil = nil, secure = false) : Marten::HTTP::Response

Allows to issue a TRACE request to the server.

Source