Last active
January 22, 2018 19:05
-
-
Save NinoScript/62ccac4c9bf7479d2317f4e448b1af94 to your computer and use it in GitHub Desktop.
Macro for running tests that use Mnesia in a transaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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