I have written a small macro for test cases.
defmodule ControllerTest do
@required [:phone, :country]
defmacro create(fields) do
quote do
without = length(unquote(@required) -- unquote(field)
if without != 0 do
Enum.map(unquote(@required), fn(field) ->
member = Enum.member?(unquote(fields), field)
if member == false do
expected_error = String.to_atom(Atom.to_string(field) <> " " <> "can't be blank")
expected = {:error, expected_error}
assert expected == {:error, expected_error}
end
end)
else
expect = {:success, "Record created"}
assert expect == {:success, "Record created"}
end
end
end
end
Its working fine without assert. But when I try to use assert it says assert is undefined. I have try import ExUnit.Assertions
inside the module but still the same assert
is undefined.
What will be the possible solution for this to use assert inside the macro?
Thanks