exunit: add pattern matching
This commit is contained in:
parent
d6365a8ef9
commit
03f63d7dcc
30
exunit.md
30
exunit.md
|
@ -65,6 +65,36 @@ flunk "This should've been an error"
|
||||||
|
|
||||||
See: [Assertions](http://devdocs.io/elixir/ex_unit/exunit.assertions)
|
See: [Assertions](http://devdocs.io/elixir/ex_unit/exunit.assertions)
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
### Pattern matching
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
setup do
|
||||||
|
{:ok, name: "John"}
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
test "it works", %{name: name} do
|
||||||
|
assert name == "John"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
describe "a block" do
|
||||||
|
setup [:my_hook]
|
||||||
|
end
|
||||||
|
|
||||||
|
defp my_hook(context) do
|
||||||
|
# Invoked in every block in "a block"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Also see
|
## Also see
|
||||||
{: .-one-column}
|
{: .-one-column}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue