From eeb5e52efbbf2ff829391096ef12d43d50e0367f Mon Sep 17 00:00:00 2001 From: thymusvulgaris <87661013+thymusvulgaris@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:39:56 +0100 Subject: [PATCH] Add Plug.Router tests * 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. --- test/plug/router_test.exs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/plug/router_test.exs b/test/plug/router_test.exs index 4a16734d..b6fed1e3 100644 --- a/test/plug/router_test.exs +++ b/test/plug/router_test.exs @@ -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_raise ArgumentError, "expected one of :to or :do to be given as option", fn -> + defmodule NoExpectedMatchOptions do + use Plug.Router + + plug :match + plug :dispatch + + match "/", foo: :bar + end + end + end + + test "error is raised with expected message when no routes are defined" do + assert_raise RuntimeError, + "no routes defined in module Plug.RouterTest.NoRoutes using Plug.Router", + fn -> + defmodule NoRoutes do + use Plug.Router + + plug :match + plug :dispatch + end + end + end + defp attach(handler_id, event) do :telemetry.attach( handler_id,