I'm writing a flexible, adapter-based error tracking library and provide a set of custom test assertion functions to make integration tests easier to work with.
I have something like
# /lib/test_helpers.ex
...
@doc """
Asserts specific exception and metadata was captured
## Example
exception = %ArgumentError{message: "test"}
exception |> MyApp.ErrorTracker.capture_exception(%{some_argument: 123})
assert_exception_captured %ArgumentError{message: "test"}, %{some_argument: 123}
"""
def assert_exception_captured(exception, extra) do
assert_receive {:exception_captured, ^exception, ^extra}, 100
end
Which will pass the exact exception to the assert_exception_captured
, but it does not work when trying to pattern match on for example the struct of the exception.
I'd like to be able to do this
...
assert_exception_captured _any_exception, %{some_argument: _}
How can I make this work with pattern matching?
Much appreciated