Created
September 24, 2016 21:19
-
-
Save renanvalentin/358c21794e7016a5b06ae169f1803585 to your computer and use it in GitHub Desktop.
Plug unit testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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