View Source FlEx.ConnTest (fl_ex v0.1.3)
This module contains all the needed stuff to test your server and all the routers
Example:
defmodule Your.Server.ConnTest do
defmacro __using__(_) do
quote do
use FlEx.ConnTest, endpoint: Your.Server.Module
setup %{conn: conn} do
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end
end
end
end
and add the line use Your.Server.ConnTest
to your test file
Summary
Functions
Creates a connection.
Creates a connection with a preset method, path and body.
Ensures the connection is recycled ans recycles in case that wasn't.
Asserts the given status code, that we have a json response and returns the decoded JSON response if one was set or sent.
Recycles the connection.
Dispatch a call to the server under the request parameters defined in params
Asserts the given status code and returns the response body if one was set or sent.
Returns the content type as long as it matches the given format.
Functions
@spec build_conn() :: Conn.t()
Creates a connection.
Creates a connection with a preset method, path and body.
@spec ensure_recycled(Conn.t()) :: Conn.t()
Ensures the connection is recycled ans recycles in case that wasn't.
Asserts the given status code, that we have a json response and returns the decoded JSON response if one was set or sent.
Examples
body = json_response(conn, 200)
assert "can't be blank" in body["errors"]
recycle(conn, headers \\ ~w(accept accept-language authorization))
View Source@spec recycle(Conn.t(), [String.t()]) :: Conn.t()
Recycles the connection.
Recycling receives a connection and returns a new connection, containing cookies and relevant information from the given one.
This emulates behaviour performed by browsers where cookies returned in the response are available in following requests.
Note recycle/1
is automatically invoked when dispatching
to the endpoint, unless the connection has already been
recycled.
Dispatch a call to the server under the request parameters defined in params
@spec response(Plug.Conn.t(), status :: integer() | atom()) :: binary()
Asserts the given status code and returns the response body if one was set or sent.
Examples
conn = get(build_conn(), "/")
assert response(conn, 200) =~ "hello world"
@spec response_content_type(Plug.Conn.t(), atom()) :: String.t()
Returns the content type as long as it matches the given format.
Examples
# Assert we have an html response with utf-8 charset
assert response_content_type(conn, :html) =~ "charset=utf-8"