Skip to content

Instantly share code, notes, and snippets.

@renanvalentin
Created September 24, 2016 21:19
Show Gist options
  • Save renanvalentin/358c21794e7016a5b06ae169f1803585 to your computer and use it in GitHub Desktop.
Save renanvalentin/358c21794e7016a5b06ae169f1803585 to your computer and use it in GitHub Desktop.
Plug unit testing
defmodule LearningElixir.Router do
use Plug.Router
if Mix.env == :dev do
use Plug.Debugger
end
plug :match
plug :dispatch
# root path
get "/" do
send_resp(conn, 200, "Hello")
end
match _ do
send_resp(conn, 404, "oops")
end
end
defmodule LearningElixir.Router do
use ExUnit.Case, async: true
use Plug.Test
alias LearningElixir.Router
@opts Router.init([])
test "returns hello text" do
response = conn(:get, "/")
|> Router.call([])
assert response.status == 200
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment