Skip to content

Commit 8bb2a6a

Browse files
committed
Update docs
1 parent 5551960 commit 8bb2a6a

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Instead of writing the following...
1212

1313
you can write...
1414

15-
`expect(name, to: be_equal_to("Douglas Adams"))`
15+
`expect(name, to: equal("Douglas Adams"))`
1616

1717
See the documentation on `Expect.Matchers` for more examples of matchers to use.
1818

@@ -32,21 +32,30 @@ end
3232

3333
You are highly encouraged to implement your own custom matchers. For the application you
3434
will build, there will surely be some interesting properties and shapes of data that
35-
will be important to verify. It might be easy to use the `be_equal_to` matcher for 99%
35+
will be important to verify. It might be easy to use the `equal()` matcher for 99%
3636
of assertions, but writing a higher-level matcher can be much more intent revealing.
3737

38-
Imagine we wanted to implement a `be_bananas()` matcher. It could look like this
38+
Imagine we are building an application that provides users with the highest quality
39+
bananas that money can buy. As part of our unit testing, it's crucial that we can
40+
verify that the output of our system is indeed a banana. It would be valuable to
41+
implement a `be_bananas()` matcher, as depending on the market the user is in
42+
the type of banana we supply them will vary (maybe they prefer it more or less ripe).
43+
44+
A simple version of our custom bananas matcher could look like this
3945

4046
```elixir
4147
defmodule MyFancyMatchers do
4248
def be_bananas() do
49+
# should return a tuple of {matcher_name, any(), fn any() -> bool}
4350
{
4451
"be bananas",
4552
Expect.Matchers.without_any_value(),
4653
fn given ->
4754
case given do
4855
"bananas" -> true
4956
"BANANAS" -> true
57+
"🍌" -> true
58+
5059
_ -> false
5160
end
5261
end
@@ -74,7 +83,7 @@ Expect ships with quite a few built-in matchers for you to use in tests
7483
* be truthy
7584
* be nil
7685
* have length
77-
* match pattern
86+
* match pattern (eg: `assert %{key: value} = %{key: "value"}`)
7887

7988
## Roadmap
8089

lib/expect.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule Expect do
1414
1515
you can write...
1616
17-
`expect(name) |> to_equal("Douglas Adams")`
17+
`expect(name, to: equal("Douglas Adams"))`
1818
1919
See the documentation on `Expect.Matchers` for more examples of matchers to use.
2020
"""
@@ -24,10 +24,12 @@ defmodule Expect do
2424
2525
Example:
2626
27-
expect(42) |> to_equal(42)
27+
```
28+
expect(42, to: equal(42))
2829
2930
# raises an error
30-
expect(42) |> to_equal("the answer to life, the universe, and everything")
31+
expect(42, to: equal("the answer to life, the universe, and everything"))
32+
```
3133
"""
3234

3335
defmacro expect(given, args \\ []) do

0 commit comments

Comments
 (0)