class Marten::Spec::Client

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(content_type : String | Nil = nil, disable_request_forgery_protection : Bool = true) #

[View source]

Instance Method Detail

def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def headers : Marten::HTTP::Headers #

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


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]