Creating test helpers
One thing I always felt was missing from Phoenix’s testing framework was the ability to simply test whether a set of routes is defined in a router. With our reflection function, it should be relatively easy to add that ability to Goldcrest.
Let’s start by defining a RouterCase
module that will house the logic for the assert_route_defined?
function. We want to be able to call this function in the most idiomatic way possible; therefore, we will write this function to work with a given router, set as a module attribute in the __using__/1
macro. This means a test module using RouterCase
will be a singleton to one router. Let’s go ahead and define that macro:
defmodule Goldcrest.ExUnit.RouterCase do defmacro __using__(opts) do quote do use ExUnit.Case @opts unquote(opts) @default_router_module __MODULE__...