diff --git a/lib/double.ex b/lib/double.ex index be51995..8149de4 100644 --- a/lib/double.ex +++ b/lib/double.ex @@ -107,11 +107,15 @@ defmodule Double do if double_opts[:verify] do source = Registry.source_for("#{dbl}") source_functions = source.module_info(:functions) - source_functions = case source_functions[:behaviour_info] do - nil -> source_functions - _ -> - behaviours = source.behaviour_info(:callbacks) - source_functions |> Keyword.merge(behaviours) + source_functions = if source_functions[:__info__] do + source_functions ++ source.__info__(:macros) + else + source_functions + end + source_functions = if source_functions[:behaviour_info] do + source_functions ++ source.behaviour_info(:callbacks) + else + source_functions end stub_arity = :erlang.fun_info(func)[:arity] matching_function = Enum.find(source_functions, fn({k, v}) -> diff --git a/test/double_test.exs b/test/double_test.exs index aeafb48..6404e0c 100644 --- a/test/double_test.exs +++ b/test/double_test.exs @@ -162,6 +162,20 @@ defmodule DoubleTest do allow(dbl, :non_existent_function, fn(_) -> :ok end) end end + + test "works with modules having macros" do + dbl = Logger + |> double + |> allow(:info, fn(_msg) -> :ok end) # Logger.info/1 is a macro + + assert :ok = dbl.info(nil) + + dbl = Mix.Task + |> double + |> allow(:run, fn(_, _) -> :ok end) + + assert :ok = dbl.run(nil, nil) + end end test "works normally when called within another process" do