Skip to content

Commit

Permalink
fix #26 by improving docs
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Jan 19, 2022
1 parent ea6ec1e commit 841651e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Only accretive/fixative changes will be made from now on.

* 2.0.next in progress
* Address [#26](https://github.com/clojure-expectations/clojure-test/issues/26) by adding an example combining `more->` and `more-of` around destructuring `ex-info` data.
* Fix [#24](https://github.com/clojure-expectations/clojure-test/issues/24) by using a local (gensym) for the actual value in `more` and `more->` so it is only evaluated once.
* Update `build-clj` to v0.6.7 and automate snapshot/release builds.

Expand Down
15 changes: 15 additions & 0 deletions doc/more.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Since the test value is threaded-first into the expressions, we can use `->` to
(/ 1 0))
```

See below for a more comprehensive example of exception testing that also uses `more-of`.

## `expect more-of`

Sometimes destructuring an (actual) test value is the easiest way to apply your expectations:
Expand Down Expand Up @@ -112,6 +114,19 @@ to `are` in `clojure.test` (but more powerful):
Although this is more verbose for this basic example, remember that the
`expected` value could also be a predicate function, a regex, a Spec, etc.

`more-of` can also be used with `more->` to provide succinct tests on Clojure's `ex-info` exceptions:

```clojure
(defexpect ex-info-tests
(expect (more-> clojure.lang.ExceptionInfo type
(more-of {:keys [status responseCode]}
409 status
4001110 responseCode) ex-data)
(throw (ex-info "boo" {:status 409 :responseCode 4001110}))))
```

In this example, the exception is threaded into `type` and the predicate is a class, and it is also threaded into `ex-data` and the predicate is a `more-of` expression that destructures that data and matches parts of it.

# Further Reading

* [Getting Started](/doc/getting-started.md)
Expand Down

0 comments on commit 841651e

Please sign in to comment.