-
Notifications
You must be signed in to change notification settings - Fork 62
/
custom_assertion_spec.exs
76 lines (61 loc) · 2 KB
/
custom_assertion_spec.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
72
73
74
75
76
Code.require_file("spec/support/assertions/be_divisor_of_assertion.ex")
Code.require_file("spec/support/assertions/be_odd_assertion.ex")
Code.require_file("spec/support/assertions/custom_assertions.ex")
defmodule CustomAssertionSpec do
use ESpec, async: true
import CustomAssertions
context "Success" do
subject 3
it "checks success with `to`" do
message = should(be_divisor_of(6))
expect(message) |> to(eq "`3` is the divisor of 6.")
end
it "checks success with `not_to`" do
message = should_not(be_divisor_of(5))
expect(message) |> to(eq "`3` is not the divisor of 5.")
end
it "checks success with `to`" do
message = should(be_odd())
expect(message) |> to(eq "`3` is odd number.")
end
it "checks success with `not_to`" do
message = 2 |> should_not(be_odd())
expect(message) |> to(eq "`2` is not odd number.")
end
end
context "Error" do
subject 5
context "with `to`" do
before do
{:shared,
expectation: fn -> should(be_divisor_of(6)) end,
message: "Expected `5` to be the divisor of `6`, but the remainder is '1'."}
end
it_behaves_like(CheckErrorSharedSpec)
end
context "with `not_to`" do
before do
{:shared,
expectation: fn -> should_not(be_divisor_of(5)) end,
message: "Expected `5` not to be the divisor of `5`, but the remainder is '0'."}
end
it_behaves_like(CheckErrorSharedSpec)
end
context "with `to`" do
before do
{:shared,
expectation: fn -> 2 |> should(be_odd()) end,
message: "Expected `2` to be the odd number, but the remainder is '0'."}
end
it_behaves_like(CheckErrorSharedSpec)
end
context "with `not_to`" do
before do
{:shared,
expectation: fn -> should_not(be_odd()) end,
message: "Expected `5` not to be the odd number, but the remainder is '1'."}
end
it_behaves_like(CheckErrorSharedSpec)
end
end
end