Skip to content

Instantly share code, notes, and snippets.

@NinoScript
Last active January 22, 2018 19:05
Show Gist options
  • Save NinoScript/62ccac4c9bf7479d2317f4e448b1af94 to your computer and use it in GitHub Desktop.
Save NinoScript/62ccac4c9bf7479d2317f4e448b1af94 to your computer and use it in GitHub Desktop.
Macro for running tests that use Mnesia in a transaction
defmacro mnesia_test(description, context \\ quote(do: _), do: block) do
quote do
test unquote(description), unquote(context) do
{:aborted, error} =
Mnesia.transaction(fn ->
unquote(block)
Mnesia.abort(:ok)
end)
case error do
:ok ->
:ok
{assertion_error, _} ->
raise(assertion_error)
{:error, assertion_error}
something_else ->
raise(something_else)
{:error, something_else}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment