Skip to content

Commit

Permalink
Add Plug.Router tests
Browse files Browse the repository at this point in the history
* Add test that asserts an error is raised with the expected
  message when Plug.Router.match/3 is not given :to or :do option.

* Add test that asserts an error is raised with the expected
  message when no routes are defined in a Plug module.
  • Loading branch information
thymusvulgaris committed Jun 25, 2024
1 parent a317031 commit ea56232
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/plug/router_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,32 @@ defmodule Plug.RouterTest do
%{route: "/", conn: %Plug.Conn{}, router: Sample}}
end

test "error is raised with expected message when match/3 is not given :to or :do option" do
assert %{message: "expected one of :to or :do to be given as option"} =
catch_error(
defmodule NoExpectedMatchOptions do
use Plug.Router

plug :match
plug :dispatch

match "/", foo: :bar
end
)
end

test "error is raised with expected message when no routes are defined" do
assert %{message: "no routes defined in module Plug.RouterTest.NoRoutes using Plug.Router"} =
catch_error(
defmodule NoRoutes do
use Plug.Router

plug :match
plug :dispatch
end
)
end

defp attach(handler_id, event) do
:telemetry.attach(
handler_id,
Expand Down

0 comments on commit ea56232

Please sign in to comment.