-
Notifications
You must be signed in to change notification settings - Fork 2
/
efx_case_test.exs
71 lines (56 loc) · 1.88 KB
/
efx_case_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
defmodule EfxCaseTest do
use ExUnit.Case
use EfxCase
alias EfxCase.EfxExample
describe "without binding effect" do
test "defaults are executed" do
assert EfxExample.get() == [1, 2, 3, 4, 5]
assert EfxExample.append_get(6) == [1, 2, 3, 4, 5, 6]
end
end
describe "binding effects" do
test "works as expected" do
bind(EfxExample, :get, fn -> [] end)
bind(EfxExample, :append_get, fn arg -> [arg] end)
assert EfxExample.get() == []
assert EfxExample.append_get(1) == [1]
end
test "works when one function is bound and the other isn't called" do
bind(EfxExample, :get, fn -> [] end)
assert EfxExample.get() == []
end
test "on multi funs" do
bind(EfxExample, :multi_fun, fn arg -> arg end)
assert EfxExample.multi_fun(:a) == :a
end
test "works with expected number of calls" do
bind(EfxExample, :get, fn -> [] end, calls: 1)
assert EfxExample.get() == []
end
test "works with expected number of calls part two" do
bind(EfxExample, :get, fn -> [] end, calls: 2)
assert EfxExample.get() == []
assert EfxExample.get() == []
end
test "allows binding one effect and defaulting the other" do
bind(EfxExample, :get, fn -> [] end)
bind(EfxExample, :append_get, {:default, 1})
assert EfxExample.get() == []
assert EfxExample.append_get(6) == [1, 2, 3, 4, 5, 6]
end
test "works in child processes" do
bind(EfxExample, :get, fn -> [] end)
bind(EfxExample, :append_get, {:default, 1})
task =
Task.async(fn ->
assert EfxExample.get() == []
assert EfxExample.append_get(6) == [1, 2, 3, 4, 5, 6]
end)
Task.await(task)
end
test "doesn't work in non child processes" do
bind(EfxExample, :get, fn -> [] end)
assert [1, 2, 3, 4, 5] = TestAgent.get()
end
end
end