Skip to content

Commit 5cea1c0

Browse files
committed
fix #33 by expanding "why?" in readme
and pushing classic expectations comparison further down Signed-off-by: Sean Corfield <[email protected]>
1 parent c261555 commit 5cea1c0

File tree

2 files changed

+73
-30
lines changed

2 files changed

+73
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Only accretive/fixative changes will be made from now on.
88

99
* 2.1.next in progress
1010
* Address [#31](https://github.com/clojure-expectations/clojure-test/issues/31) by adding more examples to `more-of`.
11+
* Address [#33](https://github.com/clojure-expectations/clojure-test/issues/33) by expanding the README introduction.
1112
* Update dev/test dependencies.
1213

1314
* 2.1.188 -- 2023-10-22

README.md

Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,43 @@ clj -Sdeps '{:deps {com.github.seancorfield/expectations {:mvn/version "RELEASE"
1717

1818
## What?
1919

20-
This library brings `expect`, `more`, `more-of`, etc from Expectations into the
21-
`clojure.test` world to be used instead of (or in addition to) the familiar `is`
22-
macro. This library has no dependencies, other than `clojure.test` itself, and
20+
This library provides a more expressive way to write tests than `clojure.test`,
21+
while still being fully compatible with `clojure.test` and all its tooling.
22+
23+
While `clojure.test` provides basic assertions using `(is (= ... ...))`
24+
and `(is (thrown? ... ...))`, Expectations additionally supports predicates,
25+
regular expressions, Specs, and collection-based tests.
26+
27+
You can either "mix'n'match" `clojure.test` and `expectations.clojure.test`
28+
features in your tests, using `deftest` from `clojure.test` or `defexpect` from
29+
this library to wrap your tests, or you can use `expectations.clojure.test` on
30+
its own, since it exposes equivalents to all of the top-level `clojure.test`
31+
functions and macros for dealing with fixtures and running tests.
32+
33+
The following are equivalent:
34+
35+
```clojure
36+
(deftest my-test-1
37+
(is (= 2 (+ 1 1)))
38+
(is (thrown? ArithmeticException (/ 1 0))))
39+
40+
(defexpect my-test-2
41+
(expect 2 (+ 1 1))
42+
(expect ArithmeticException (/ 1 0)))
43+
```
44+
45+
But you can also do things like:
46+
47+
```clojure
48+
(defexpect my-test-3
49+
(expect even? (+ 1 1))
50+
(expect #"foo" "It's foobar!")
51+
(expect ::adult-age 42)) ; ::adult-age is a Spec
52+
```
53+
54+
See the example REPL session below for more details.
55+
56+
This library has no dependencies, other than `clojure.test` itself, and
2357
should be compatible with all existing `clojure.test`-based tooling in editors
2458
and command-line tools.
2559

@@ -29,9 +63,6 @@ Works in self-hosted ClojureScript (specifically,
2963
[`planck`](https://planck-repl.org)). See
3064
[Getting Started with ClojureScript](/doc/getting-started-cljs.md) for details.
3165

32-
You can either use `deftest` from `clojure.test`, or `defexpect` from
33-
this library to wrap your tests.
34-
3566
## Example REPL Session
3667

3768
What follows is an example REPL session showing some of what this library provides. For more detailed documentation, start with [Getting Started](/doc/getting-started.md) and work your way through the sections listed there.
@@ -78,7 +109,7 @@ What follows is an example REPL session showing some of what this library provid
78109

79110
(defexpect named String (name :foo))
80111

81-
;; the expected outcome can be a Spec (require Clojure 1.9 or later):
112+
;; the expected outcome can be a Spec:
82113

83114
(s/def ::value (s/and pos-int? #(< % 100)))
84115
(defexpect small-value
@@ -164,36 +195,27 @@ expected: (=? even? (+ 1 1 1))
164195
nil
165196
```
166197

167-
## Compatibility with Expectations
198+
## Why?
168199

169-
`expectations.clojure.test` supports the following features from Expectations so far:
200+
TL;DR: Because I liked the ["Classic" Expectations library](https://clojure-expectations.github.io) but didn't like having to use custom, Expectations-specific tooling.
170201

171-
* simple equality test
172-
* simple predicate test
173-
* spec test (using a keyword that identifies a spec)
174-
* class test -- see `named` above
175-
* exception test -- see `divide-by-zero` above
176-
* regex test -- see `regex-1` and `regex-2` above
177-
* `(expect expected-expr (from-each [a values] (actual-expr a)))`
178-
* `(expect expected-expr (in actual-expr))` -- see `collections` above
179-
* `(expect (more-of destructuring e1 a1 e2 a2 ...) actual-expr)`
180-
* `(expect (more-> e1 a1 e2 a2 ...) actual-expr)` -- where `actual-expr` is threaded into each `a1`, `a2`, ... expression
181-
* `(expect (more e1 e2 ...) actual-expr)`
182-
* `(expect expected-expr (side-effects [fn1 fn2 ...] actual-expr))`
202+
### Why not just use `clojure.test`?
183203

184-
Read [the Expectations documentation](https://clojure-expectations.github.io/)
185-
for more details of these features.
204+
`clojure.test` is a great library for writing tests in Clojure. It's simple,
205+
it's built-in, and it's widely supported by the Clojure ecosystem. However, it
206+
only provides basic assertions and doesn't support some of the more advanced
207+
testing features that Expectations does.
186208

187-
## Why?
209+
### Why not just use the "Classic" Expectations library?
188210

189211
Given the streamlined simplicity of Expectations, you might wonder why you
190212
would want to migrate your Expectations test suite to `clojure.test`-style
191213
named tests? The short answer is **tooling**! Whilst Expectations has
192214
well-maintained, stable plugins for Leiningen and Boot, as well as an Emacs mode,
193215
the reality is that Clojure tooling is constantly evolving and most of those
194-
tools -- such as the excellent [CIDER](https://cider.readthedocs.io/en/latest/),
216+
tools -- such as the excellent [CIDER](https://docs.cider.mx/),
195217
[Cursive](https://cursive-ide.com/),
196-
[Chlorine](https://atom.io/packages/chlorine) (for Atom),
218+
[Calva](https://calva.io/) (for VS Code),
197219
and [Cognitect's `test-runner`](https://github.com/cognitect-labs/test-runner) --
198220
are going to focus on Clojure's built-in testing library first.
199221
Support for the original form of Expectations, using unnamed tests, is
@@ -214,7 +236,27 @@ macro). Whilst this goes against the [Test Names
214236
philosophy](https://clojure-expectations.github.io/odds-ends.html) that Expectations was created with, it buys us a lot in terms of
215237
tooling support!
216238

217-
## Differences from Expectations
239+
## Compatibility with "Classic" Expectations
240+
241+
`expectations.clojure.test` supports the following features from the "Classic" Expectations library so far:
242+
243+
* simple equality test
244+
* simple predicate test
245+
* spec test (using a keyword that identifies a spec)
246+
* class test -- see `named` above
247+
* exception test -- see `divide-by-zero` above
248+
* regex test -- see `regex-1` and `regex-2` above
249+
* `(expect expected-expr (from-each [a values] (actual-expr a)))`
250+
* `(expect expected-expr (in actual-expr))` -- see `collections` above
251+
* `(expect (more-of destructuring e1 a1 e2 a2 ...) actual-expr)`
252+
* `(expect (more-> e1 a1 e2 a2 ...) actual-expr)` -- where `actual-expr` is threaded into each `a1`, `a2`, ... expression
253+
* `(expect (more e1 e2 ...) actual-expr)`
254+
* `(expect expected-expr (side-effects [fn1 fn2 ...] actual-expr))`
255+
256+
Read [the Expectations documentation](https://clojure-expectations.github.io/)
257+
for more details of these features.
258+
259+
## Differences from "Classic" Expectations
218260

219261
Aside from the obvious difference of providing names for tests -- essential for
220262
compatibility with `clojure.test`-based tooling -- here are the other differences
@@ -235,7 +277,7 @@ To test, run `clj -X:test` (tests against Clojure 1.9).
235277
Multi-version testing:
236278

237279
```
238-
for v in 1.9 1.10
280+
for v in 1.9 1.10 1.11 1.12
239281
do
240282
clojure -X:test:$v
241283
done
@@ -244,7 +286,7 @@ done
244286
You can also run the tests with Humane Test Output enabled but you need to exclude the negative tests because they assume things about the test report data that HTO modifies:
245287

246288
```
247-
for v in 1.9 1.10
289+
for v in 1.9 1.10 1.11 1.12
248290
do
249291
clojure -X:test:$v:humane :excludes '[:negative]'
250292
done
@@ -292,6 +334,6 @@ This will set you up with `defexpect` and `expect`. Add others as required.
292334

293335
## License & Copyright
294336

295-
Copyright © 2018-2023 Sean Corfield, all rights reserved.
337+
Copyright © 2018-2024 Sean Corfield, all rights reserved.
296338

297339
Distributed under the Eclipse Public License version 1.0.

0 commit comments

Comments
 (0)