[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 7526198 029/340: Spies: :and-throw-error
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 7526198 029/340: Spies: :and-throw-error |
Date: |
Thu, 16 Dec 2021 14:58:58 -0500 (EST) |
branch: elpa/buttercup
commit 752619812cd9f0d4d954cc31a87e46607a72e3dc
Author: Jorgen Schaefer <contact@jorgenschaefer.de>
Commit: Jorgen Schaefer <contact@jorgenschaefer.de>
Spies: :and-throw-error
---
README.md | 21 +++++++++++++++++++++
buttercup-test.el | 9 +++++++++
buttercup.el | 4 ++++
3 files changed, 34 insertions(+)
diff --git a/README.md b/README.md
index 8eaad06..03c3f87 100644
--- a/README.md
+++ b/README.md
@@ -431,6 +431,27 @@ function.
(expect fetched-bar :to-equal 1001))))
```
+### Spies: `:and-throw-error`
+
+With the keyword argument `:and-throw-error`, all calls to the spy
+will `signal` the specified value as an error.
+
+```Lisp
+(describe "A spy, when configured to throw an error"
+ (let (bar set-bar get-bar fetched-bar)
+ (before-each
+ (fset 'set-bar (lambda (val)
+ (setq bar val)))
+ (fset 'get-bar (lambda ()
+ bar))
+
+ (spy-on 'get-bar :and-throw-error 'error))
+
+ (it "throws the error"
+ (expect (lambda () (get-bar))
+ :to-throw 'error))))
+```
+
## Test Runners
diff --git a/buttercup-test.el b/buttercup-test.el
index 3fc2119..fc8d10c 100644
--- a/buttercup-test.el
+++ b/buttercup-test.el
@@ -419,3 +419,12 @@
(expect (test-function 2 3)
:to-equal
1001)))
+
+(describe "The :and-throw-error keyword functionality"
+ (before-each
+ (spy-on 'test-function :and-throw-error 'error))
+
+ (it "throws an error when called"
+ (expect (lambda () (test-function 1 2))
+ :to-throw
+ 'error "Stubbed error")))
diff --git a/buttercup.el b/buttercup.el
index 83e3c6e..d02bc07 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -384,6 +384,10 @@ A disabled spec is not run."
(setq new-value (lambda (&rest args)
(buttercup--spy-add-call new-value args)
(apply arg args))))
+ ((eq keyword :and-throw-error)
+ (setq new-value (lambda (&rest args)
+ (buttercup--spy-add-call new-value args)
+ (signal arg "Stubbed error"))))
((not keyword)
(setq new-value (lambda (&rest args)
(buttercup--spy-add-call new-value args)
- [nongnu] elpa/buttercup 1882d6f 013/340: Comment cleanup. Also, make elisp lexically scoped., (continued)
- [nongnu] elpa/buttercup 1882d6f 013/340: Comment cleanup. Also, make elisp lexically scoped., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c5a9f26 003/340: Add first set of unit tests., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 36522b9 006/340: Add .travis.yml, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f44e65d 004/340: Unit tests for define-matcher and apply-matcher., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d3cd12a 019/340: Tests for the buttercup-describe function, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 3772ad5 014/340: Use eval-region instead of eval-buffer., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8aa87c8 026/340: Spy :and-call-through, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 683614d 018/340: Tests for the describe macro., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0221830 023/340: Remove setup and teardown from ROADMAP.md., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 695e444 016/340: buttercup-markdown-runner: Use setq, not setq-local., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7526198 029/340: Spies: :and-throw-error,
ELPA Syncer <=
- [nongnu] elpa/buttercup 77d1dac 017/340: Test buttercup-suite-add-child., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c1abc2a 033/340: Refactoring of spy context accessors., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f314737 035/340: ROADMAP.md: Remove spies section, as it is done., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4bd24e7 037/340: ROADMAP cleanup., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 55b87ec 039/340: Removed ROADMAP.md. This is now tracked in issues., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 993ddda 040/340: Add .gitignore, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 1dcd2cd 041/340: Prepare release, add bumpversion and pkg.el, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f046eef 042/340: Bump version: 0.1 → 1.0, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 537b729 044/340: Merge pull request #6 from myeffort/master, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bcaa087 046/340: Add buttercup executable to run buttercup tests more easily., ELPA Syncer, 2021/12/16