class Marten::Spec::Client
- Marten::Spec::Client
- Reference
- Object
Overview
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
.
Defined in:
marten/spec/client.crConstructors
Instance Method Summary
-
#cookies
Returns a
Marten::HTTP::Cookies
object that can be leveraged to set cookies that should be used by the client. -
#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.
-
#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.
-
#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.
-
#headers : Marten::HTTP::Headers
Returns a
Marten::HTTP::Headers
object that can be leveraged to set headers that should bet for each request. -
#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.
-
#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.
-
#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.
-
#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.
-
#session
Returns a session store object for the client.
-
#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.
Constructor Detail
Instance Method Detail
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.
Allows to issue a DELETE request to the server.
Allows to issue a GET request to the server.
Allows to issue a HEAD request to the server.
Returns a Marten::HTTP::Headers
object that can be leveraged to set headers that should bet for each request.
Allows to issue an OPTIONS request to the server.
Allows to issue a PATCH request to the server.
Allows to issue a POST request to the server.
Allows to issue a PUT request to the server.
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.
Allows to issue a TRACE request to the server.