You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/more.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,13 @@ If you have multiple predicates that you expect to be satisfied by a given expre
10
10
(expect (more vector? not-empty) [123])
11
11
```
12
12
13
-
This expects the (actual) test value to be a vector and also to be non-empty (we could have specified `seq` there just as easily). This can be particularly powerful when combined with `from-each` to check that multiple expectations hold for computations applied to multiple input values.
13
+
This expects the (actual) test value to be a vector and also to be non-empty (we could have specified `seq` there just as easily). This can be particularly powerful when combined with `from-each` to check that multiple expectations hold for computations applied to multiple input values:
14
+
15
+
```clojure
16
+
(expect (more vector? not-empty)
17
+
(from-each [n [123]]
18
+
(into [] (range n))))
19
+
```
14
20
15
21
> If you have expectations that should hold for **all** input values, you might want to look at [`clojure.test.check`](https://github.com/clojure/test.check) instead.
16
22
@@ -82,6 +88,30 @@ Some simpler examples (taken from Expectations' original documentation):
82
88
[123])
83
89
```
84
90
91
+
`more-of` can be used with `from-each` to provide functionality similar
92
+
to `are` in `clojure.test` (but more powerful):
93
+
94
+
```clojure
95
+
(deftestare-example
96
+
(are [expected start end]
97
+
(= expected (range start end))
98
+
[0123] 04
99
+
[] 00
100
+
[123] 14))
101
+
102
+
(defexpectequivalent-to-are
103
+
(expect (more-of [expected actual]
104
+
expected actual)
105
+
(from-each [[expected start end]
106
+
[[[0123] 04]
107
+
[[] 00]
108
+
[[123] 14]]]
109
+
[expected (range start end)])))
110
+
```
111
+
112
+
Although this is more verbose for this basic example, remember that the
113
+
`expected` value could also be a predicate function, a regex, a Spec, etc.
0 commit comments