Skip to content

Commit

Permalink
Match on error message rather than exception class
Browse files Browse the repository at this point in the history
  • Loading branch information
thymusvulgaris committed Jun 25, 2024
1 parent c1d9fe8 commit f8993a5
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions test/plug/router_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -615,27 +615,29 @@ defmodule Plug.RouterTest do
end

test "ArgumentError is raised when match/3 is not given :to or :do option" do
assert_raise ArgumentError, fn ->
defmodule NoExpectedMatchOptions do
use Plug.Router
%{message: "expected one of :to or :do to be given as option"} =
catch_error(
defmodule NoExpectedMatchOptions do
use Plug.Router

plug :match
plug :dispatch
plug :match
plug :dispatch

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

test "RuntimeError is raised when no routes are defined" do
assert_raise RuntimeError, fn ->
defmodule NoRoutes do
use Plug.Router

plug :match
plug :dispatch
end
end
%{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
Expand Down

0 comments on commit f8993a5

Please sign in to comment.