Skip to content

Commit 1a9a264

Browse files
committed
Merge pull request #3756 from sunaku/patch-1
assert_raise: document that message can be regex
2 parents 0a10680 + feeea8c commit 1a9a264

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,18 @@ defmodule ExUnit.Assertions do
376376

377377
@doc """
378378
Asserts the `exception` is raised during `function` execution with
379-
the `expected_message`. Returns the rescued exception, fails otherwise.
379+
the expected `message`, which can be a `Regex` or an exact `String`.
380+
Returns the rescued exception, fails otherwise.
380381
381382
## Examples
382383
383384
assert_raise ArithmeticError, "bad argument in arithmetic expression", fn ->
384385
1 + "test"
385386
end
387+
388+
assert_raise RuntimeError, ~r/^Today's lucky number is 0\.\d+!$/, fn ->
389+
raise "Today's lucky number is #{:random.uniform}!"
390+
end
386391
"""
387392
def assert_raise(exception, message, function) when is_function(function) do
388393
error = assert_raise(exception, function)

0 commit comments

Comments
 (0)