I wrote this test case:
assert_raise ArgumentError, myFn(a,b)
but it does not evaluate in the way I'd expect. myFn
raises an ArgumentError (do: raise ArgumentError
), but it is not caught by assert_raise
.
The example in the docs works just fine:
assert_raise ArithmeticError, fn ->
1 + "test"
end
From the documentation:
assert_raise(exception, function)
Asserts theexception
is raised duringfunction
execution. Returns the rescued exception, fails otherwise
I'm guessing that in my test case, the arguments are evaluated first. But how should I've written it?
assert_rise
is not a macro, but normal function: github.com/elixir-lang/elixir/blob/… This means that if you just passmyFn(a, b)
it will be evaluated and the value will be passed toassert_rise
which is already too late :) – Beatify