[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 20b87dd 031/340: Refactoring of spy-on to be mor
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 20b87dd 031/340: Refactoring of spy-on to be more concise and DRY. |
Date: |
Thu, 16 Dec 2021 14:58:59 -0500 (EST) |
branch: elpa/buttercup
commit 20b87dd6ab7ace1d45d8d76eaad7cad15702e516
Author: Jorgen Schaefer <contact@jorgenschaefer.de>
Commit: Jorgen Schaefer <contact@jorgenschaefer.de>
Refactoring of spy-on to be more concise and DRY.
---
buttercup-test.el | 7 +----
buttercup.el | 79 +++++++++++++++++++++++++++++--------------------------
2 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/buttercup-test.el b/buttercup-test.el
index c361a0b..5e01ecd 100644
--- a/buttercup-test.el
+++ b/buttercup-test.el
@@ -432,9 +432,4 @@
(it "throws an error when called"
(expect (lambda () (test-function 1 2))
:to-throw
- 'error "Stubbed error")))
-
-
-
- )
- )
+ 'error "Stubbed error")))))
diff --git a/buttercup.el b/buttercup.el
index 0885be6..66cbf74 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -374,39 +374,46 @@ A disabled spec is not run."
current-buffer)
(defun spy-on (symbol &optional keyword arg)
- (let ((old-value (symbol-function symbol))
- (new-value nil))
- (cond
- ((eq keyword :and-call-through)
- (setq new-value (lambda (&rest args)
- (let ((return-value (apply old-value args)))
- (buttercup--spy-add-call new-value
- args
- return-value)
- return-value))))
- ((eq keyword :and-return-value)
- (setq new-value (lambda (&rest args)
- (buttercup--spy-add-call new-value
- args
- arg)
- arg)))
- ((eq keyword :and-call-fake)
- (setq new-value (lambda (&rest args)
- (let ((return-value (apply arg args)))
- (buttercup--spy-add-call new-value
- args
- return-value)
- return-value))))
- ((eq keyword :and-throw-error)
- (setq new-value (lambda (&rest args)
- (buttercup--spy-add-call new-value args nil)
- (signal arg "Stubbed error"))))
- ((not keyword)
- (setq new-value (lambda (&rest args)
- (buttercup--spy-add-call new-value args nil)
- nil))))
- (fset symbol new-value)
- (buttercup--add-cleanup (lambda () (fset symbol old-value)))))
+ (cond
+ ((eq keyword :and-call-through)
+ (let ((orig (symbol-function symbol)))
+ (buttercup--spy-on-and-call-fake symbol
+ (lambda (&rest args)
+ (apply orig args)))))
+ ((eq keyword :and-return-value)
+ (buttercup--spy-on-and-call-fake symbol
+ (lambda (&rest args)
+ arg)))
+ ((eq keyword :and-call-fake)
+ (buttercup--spy-on-and-call-fake symbol
+ arg))
+ ((eq keyword :and-throw-error)
+ (buttercup--spy-on-and-call-fake symbol
+ (lambda (&rest args)
+ (signal arg "Stubbed error"))))
+ (t
+ (buttercup--spy-on-and-call-fake symbol
+ (lambda (&rest args)
+ nil)))))
+
+(defun buttercup--spy-on-and-call-fake (spy fake-function)
+ (let ((orig-function (symbol-function spy)))
+ (fset spy (buttercup--make-spy fake-function))
+ (buttercup--add-cleanup (lambda ()
+ (fset spy orig-function)))))
+
+(defun buttercup--make-spy (fake-function)
+ (let (this-spy-function)
+ (setq this-spy-function
+ (lambda (&rest args)
+ (let ((return-value (apply fake-function args)))
+ (buttercup--spy-add-call
+ this-spy-function
+ (make-spy-context :args args
+ :return-value return-value
+ :current-buffer (current-buffer)))
+ return-value)))
+ this-spy-function))
(defun buttercup--add-cleanup (function)
(if buttercup--current-suite
@@ -415,12 +422,10 @@ A disabled spec is not run."
(append buttercup--cleanup-forms
(list function)))))
-(defun buttercup--spy-add-call (spy args return-value)
+(defun buttercup--spy-add-call (spy context)
(puthash spy
(append (buttercup--spy-calls spy)
- (list (make-spy-context :current-buffer (current-buffer)
- :args args
- :return-value return-value)))
+ (list context))
buttercup--spy-calls))
(defun buttercup--spy-calls (spy)
- [nongnu] elpa/buttercup 7e20ff1 021/340: ROADMAP.md: New file., (continued)
- [nongnu] elpa/buttercup 7e20ff1 021/340: ROADMAP.md: New file., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 764d6aa 020/340: Tests for the it macro and buttercup-it function., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d5572a6 034/340: Refactoring of the cleanup code., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b75b3e9 036/340: Add a discovery test runner., ELPA Syncer, 2021/12/16
- [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 <=
- [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, 2021/12/16
- [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