Update ExUnit cheatsheet: Demonstrate named setup context more clearly (#850)
This commit is contained in:
parent
05bca6d01c
commit
a78dab76cf
17
exunit.md
17
exunit.md
|
@ -85,13 +85,22 @@ end
|
||||||
|
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
describe "a block" do
|
|
||||||
setup [:my_hook]
|
defp my_hook(_context) do
|
||||||
|
# Invoked in every block in "a block"
|
||||||
|
{:ok, name: "John", age: 54}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp my_hook(context) do
|
describe "a block" do
|
||||||
# Invoked in every block in "a block"
|
setup [:my_hook]
|
||||||
|
|
||||||
|
test "John's age", context do
|
||||||
|
assert context[:name] == "John"
|
||||||
|
assert context[:age] == 54
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue