Packages

A collection of extra utilities and extensions to the Elixir standard library

Current section

Files

Jump to
extra lib ex_unit extra.ex
Raw

lib/ex_unit/extra.ex

defmodule ExUnit.Extra do
@moduledoc """
Extensions to ExUnit for testing purposes.
"""
@assert_receive_timeout Application.get_env(:ex_unit, :assert_receive_timeout, 100)
@doc """
Allows for a receive of either pattern to pass, otherwise raises.
"""
defmacro assert_receive_either(pattern_a, pattern_b, timeout \\ @assert_receive_timeout) do
quote do
timeout = unquote(timeout)
receive do
unquote(pattern_a) ->
:ok
unquote(pattern_b) ->
:ok
after
timeout ->
raise "No message matching either #{inspect unquote(pattern_a)} or #{inspect unquote(pattern_b)} after #{timeout}ms"
end
end
end
end