Skip to content

Commit 1b7a734

Browse files
committed
Improve ExUnit Callbacks docs
1 parent 7cf57ec commit 1b7a734

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/ex_unit/lib/ex_unit/callbacks.ex

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ defmodule ExUnit.Callbacks do
33
Defines ExUnit callbacks.
44
55
This module defines the `setup/1`, `setup/2`, `setup_all/1`, and
6-
`setup_all/2` callbacks, as well as the `on_exit/2`, `start_supervised/2`,
7-
`stop_supervised/1` and `start_link_supervised!/2` functions.
6+
`setup_all/2` macros, as well as process lifecycle and management
7+
functions, such as `on_exit/2`, `start_supervised/2`, `stop_supervised/1`
8+
and `start_link_supervised!/2`.
89
910
The setup callbacks may be used to define [test fixtures](https://en.wikipedia.org/wiki/Test_fixture#Software)
1011
and run any initialization code which help bring the system into a known
@@ -56,13 +57,15 @@ defmodule ExUnit.Callbacks do
5657
5758
## Context
5859
59-
If `setup_all` or `setup` return a keyword list, a map, or a tuple in the shape
60-
of `{:ok, keyword() | map()}`, the keyword list or map will be merged into the
61-
current context and will be available in all subsequent `setup_all`,
62-
`setup`, and the `test` itself.
60+
`setup_all` or `setup` may return one of:
6361
64-
Returning `:ok` leaves the context unchanged (in `setup` and `setup_all`
65-
callbacks).
62+
* the atom `:ok`
63+
* a keyword list or map
64+
* a tuple in the shape of `{:ok, keyword() | map()}`
65+
66+
If a keyword list or map is returned, it be merged into the current context
67+
and will be available in all subsequent `setup_all`, `setup`, and the `test`
68+
itself.
6669
6770
Returning anything else from `setup_all` will force all tests to fail,
6871
while a bad response from `setup` causes the current test to fail.
@@ -728,7 +731,7 @@ defmodule ExUnit.Callbacks do
728731

729732
defp raise_merge_failed!(mod, kind, return_value) do
730733
raise "expected ExUnit #{kind} callback in #{inspect(mod)} to " <>
731-
"return :ok | keyword | map, got #{inspect(return_value)} instead"
734+
"return the atom :ok, a keyword, or a map, got #{inspect(return_value)} instead"
732735
end
733736

734737
defp raise_merge_reserved!(mod, kind, key, value) do

lib/ex_unit/test/ex_unit/callbacks_test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ defmodule ExUnit.CallbacksTest do
394394

395395
assert output =~
396396
"** (RuntimeError) expected ExUnit setup callback in " <>
397-
"ExUnit.CallbacksTest.SetupErrorTest to return :ok | keyword | map, " <>
397+
"ExUnit.CallbacksTest.SetupErrorTest to return the atom :ok, a keyword, or a map, " <>
398398
"got {:ok, \"foo\"} instead"
399399

400400
# Make sure that at least the right file where the setup/setup_all call is defined is included
@@ -414,7 +414,7 @@ defmodule ExUnit.CallbacksTest do
414414

415415
assert output =~
416416
"** (RuntimeError) expected ExUnit setup_all callback in " <>
417-
"ExUnit.CallbacksTest.SetupAllErrorTest to return :ok | keyword | map, " <>
417+
"ExUnit.CallbacksTest.SetupAllErrorTest to return the atom :ok, a keyword, or a map, " <>
418418
"got {:ok, \"foo\"} instead"
419419

420420
# Make sure that at least the right file where the setup/setup_all call is defined is included

0 commit comments

Comments
 (0)