Provides an easy to way set up responses when using Bypass in your tests.
The package can be installed by adding bypass_routes
to your list of dependencies in mix.exs
:
def deps do
[
{:bypass_routes, "~> 0.1.0", only: :test},
]
end
Once your bypass
is set up as usual,
you can call bypass_routes/1
to configure your responses:
test "hello world", %{bypass: bypass} do
bypass_routes(bypass) do
plug Plug.Parsers, parsers: [:json], json_decoder: Poison
post "/message" do
send_resp conn, 200, conn.params["message"]
end
end
headers = %{"Content-Type" => "application/json"}
body = Poison.encode!(%{"message" => "Hello World"})
assert %{body: "Hello World"} = HTTPoison.post!("http://localhost:#{bypass.port}/message", body, headers)
end
See the docs for Plug.Router
for details about route matching.