1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-06-15 14:47:53 +02:00

exunit: add pattern matching

This commit is contained in:
Rico Sta. Cruz 2018-02-12 15:34:00 +08:00
parent d6365a8ef9
commit 03f63d7dcc
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A

View File

@ -65,6 +65,36 @@ flunk "This should've been an error"
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
{: .-one-column}