     assert_received {:email, _}
   end
 
-  @spec assert_email_sent(Email.t() | Keyword.t()) :: :ok | tuple | no_return
+  @spec assert_email_sent(Email.t() | Keyword.t() | (Email.t() -> boolean())) :: :ok | tuple | no_return
 
   @doc ~S"""
   Asserts `email` was sent.
 
-  You pass a keyword list to match on specific params.
+  You can pass a keyword list to match on specific params
+  or an anonymous function that returns a boolean.
 
   ## Examples
 


      # assert an email with specific field(s) was sent
      iex> assert_email_sent subject: "Hello, Avengers!"
  """
  def assert_email_sent(%Email{} = email) do
    assert_received {:email, ^email}

    Enum.each(params, &assert_equal(email, &1))
  end

  def assert_email_sent(fun) when is_function(fun, 1) do
    assert_received {:email, email}
    assert fun.(email)
  end

  defp assert_equal(email, {:subject, value}),
    do: assert(email.subject == value)

