[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 7cdb219 028/340: Spies: :and-call-fake
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 7cdb219 028/340: Spies: :and-call-fake |
Date: |
Thu, 16 Dec 2021 14:58:58 -0500 (EST) |
branch: elpa/buttercup
commit 7cdb2191767f051c990b8f6ea76e94f6377d0ad0
Author: Jorgen Schaefer <contact@jorgenschaefer.de>
Commit: Jorgen Schaefer <contact@jorgenschaefer.de>
Spies: :and-call-fake
---
README.md | 30 ++++++++++++++++++++++++++++++
buttercup-test.el | 14 ++++++++++++++
buttercup.el | 4 ++++
3 files changed, 48 insertions(+)
diff --git a/README.md b/README.md
index 70c6bbd..8eaad06 100644
--- a/README.md
+++ b/README.md
@@ -402,6 +402,36 @@ spied-on function should return.
(expect fetched-bar :to-equal 745))))
```
+### Spies: `:and-call-fake`
+
+The keyword argument `:and-call-fake` delegates calls to a supplied
+function.
+
+```Lisp
+(describe "A spy, when configured with an alternate implementation"
+ (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-call-fake (lambda () 1001))
+
+ (set-bar 123)
+ (setq fetched-bar (get-bar)))
+
+ (it "tracks that the spy was called"
+ (expect 'get-bar :to-have-been-called))
+
+ (it "should not affect other functions"
+ (expect bar :to-equal 123))
+
+ (it "when called returns the requested value"
+ (expect fetched-bar :to-equal 1001))))
+```
+
+
## Test Runners
Evaluating `describe` forms just stores the suites. You need to use a
diff --git a/buttercup-test.el b/buttercup-test.el
index 5fe85b8..3fc2119 100644
--- a/buttercup-test.el
+++ b/buttercup-test.el
@@ -405,3 +405,17 @@
(expect (test-function 2 3)
:to-equal
23)))
+
+(describe "The :and-call-fake keyword functionality"
+ (before-each
+ (spy-on 'test-function :and-call-fake (lambda (a b) 1001)))
+
+ (it "tracks calls to the function"
+ (test-function 42 23)
+
+ (expect 'test-function :to-have-been-called))
+
+ (it "returns the specified value"
+ (expect (test-function 2 3)
+ :to-equal
+ 1001)))
diff --git a/buttercup.el b/buttercup.el
index 72f02c7..83e3c6e 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -380,6 +380,10 @@ A disabled spec is not run."
(setq new-value (lambda (&rest args)
(buttercup--spy-add-call new-value args)
arg)))
+ ((eq keyword :and-call-fake)
+ (setq new-value (lambda (&rest args)
+ (buttercup--spy-add-call new-value args)
+ (apply arg args))))
((not keyword)
(setq new-value (lambda (&rest args)
(buttercup--spy-add-call new-value args)
- [nongnu] elpa/buttercup 7eecb96 038/340: Remove commented-out backtrace code from buttercup.el., (continued)
- [nongnu] elpa/buttercup 7eecb96 038/340: Remove commented-out backtrace code from buttercup.el., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 3483449 045/340: Typo fix., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 84002e9 054/340: Add parent relations to specs and suites., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a7d9813 010/340: Add cl-defstruct compatibility alias., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fd70ccf 002/340: Specs are now structs., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup ba40ff8 027/340: Spies: :and-return-value, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 20b87dd 031/340: Refactoring of spy-on to be more concise and DRY., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bb31c85 043/340: Edebugable., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5d369cd 007/340: Do not use emacs-snapshot from EVM, that's slow., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 07b1ee6 008/340: Add compatibility definition for define-error, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7cdb219 028/340: Spies: :and-call-fake,
ELPA Syncer <=
- [nongnu] elpa/buttercup 5db449f 025/340: Spies, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d580e5c 011/340: Add build status badge., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 3637e3d 015/340: Add more extensive matcher tests to the README., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a277b0e 022/340: Setup and teardown: before-each, after-each, before-all, after-all, ELPA Syncer, 2021/12/16
- [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