[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup fc19598 225/340: Add examples for checking retur
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup fc19598 225/340: Add examples for checking return value and thrown signal of a spy |
Date: |
Thu, 16 Dec 2021 14:59:39 -0500 (EST) |
branch: elpa/buttercup
commit fc19598e89805975596c055fd9bed81ef9d1ff1c
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Add examples for checking return value and thrown signal of a spy
---
docs/writing-tests.md | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/docs/writing-tests.md b/docs/writing-tests.md
index cb72b28..643303c 100644
--- a/docs/writing-tests.md
+++ b/docs/writing-tests.md
@@ -524,7 +524,8 @@ will `signal` the specified value as an error.
### Other tracking properties
Every call to a spy is tracked and exposed using the `spy-calls`
-accessor.
+accessor. This tracks both successful calls and calls that throw
+errors.
`spy-calls-any` returns `nil` if the spy has not been called at all,
and then `t` once at least one call happens. `spy-calls-count` returns
@@ -536,6 +537,10 @@ current buffer and arguments passed to all calls.
the most recent call. `spy-calls-first` returns the current buffer and
arguments for the first call.
+The spy context structs returned by these functions have 4 slots:
+`args`, `return-value`, `thrown-signal`, and `current-buffer`. See
+below for examples accessing these.
+
Finally, `spy-calls-reset` clears all tracking for a spy.
```Emacs-Lisp
@@ -619,6 +624,24 @@ Finally, `spy-calls-reset` clears all tracking for a spy.
:args '(123)
:return-value nil)))
+ (it "tracks the return values and error signals of each call"
+ ;; Set up `set-foo' so that it can either return a value or throw
+ ;; an error
+ (spy-on 'set-foo :and-call-fake
+ (lambda (val &rest ignored)
+ (if (>= val 0)
+ val
+ (error "Value must not be negative"))))
+ (expect (set-foo 1) :to-be 1)
+ (expect (set-foo -1) :to-throw 'error)
+ (expect
+ (spy-context-return-value (spy-calls-first 'set-foo))
+ :to-be 1)
+ (expect
+ (spy-context-thrown-signal
+ (spy-calls-most-recent 'set-foo))
+ :to-equal (list 'error "Value must not be negative")))
+
(it "can be reset"
(set-foo 123)
(set-foo 456 "baz")
- [nongnu] elpa/buttercup 7cea4c6 192/340: Test buttercup-run, (continued)
- [nongnu] elpa/buttercup 7cea4c6 192/340: Test buttercup-run, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b410c78 193/340: Separate return code from reporter, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9b230dc 202/340: Fix the "should print the elapsed time for all specs" test, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9d172a7 205/340: Merge pull request #145 from snogge/test-fixes, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c100fad 210/340: Implement buttercup-suppress-warning-capture, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c994aea 212/340: Add LICENSE file., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d9ce620 213/340: Merge branch 'license-file' into master, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 49f01fc 219/340: Merge branch 'master' into test-emacs-26.3, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 25462dd 223/340: Record calls to spied-on functions that throw errors, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bf48137 224/340: Add some tests for error-call recording, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fc19598 225/340: Add examples for checking return value and thrown signal of a spy,
ELPA Syncer <=
- [nongnu] elpa/buttercup 6590360 226/340: Fix a few typos and other small errors, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8a28489 230/340: Bump version: 1.18 → 1.19, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0e40587 231/340: Tweak the spy-contexts to be more backward compatible, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 60028db 236/340: docs: Clarify the spy lifespan in writing-tests.md, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9c4b473 237/340: test: Add missing apostrophe in spec title, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 90654ec 238/340: Update some docstrings, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 178c795 242/340: README: Add '-L .' to test runner example, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fc4276a 247/340: Make it possible to abort test run cleanly, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup dbcd3d4 256/340: Calculate total test run time with current-time, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c83ba7d 268/340: Extract function buttercup-elapsed-time-string, ELPA Syncer, 2021/12/16