@@ -12,7 +12,7 @@ Instead of writing the following...
1212
1313you can write...
1414
15- ` expect(name, to: be_equal_to ("Douglas Adams")) `
15+ ` expect(name, to: equal ("Douglas Adams")) `
1616
1717See the documentation on ` Expect.Matchers ` for more examples of matchers to use.
1818
3232
3333You are highly encouraged to implement your own custom matchers. For the application you
3434will 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%
3636of 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
4147defmodule 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
0 commit comments