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:
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)
|
||||
|
||||
## 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}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user