Skip to content

Commit

Permalink
Merge pull request jorgenschaefer#147 from snogge/suite-local-function
Browse files Browse the repository at this point in the history
test: Do not leak functions from "The Spy " suite
  • Loading branch information
snogge authored Sep 26, 2019
2 parents d2b6692 + e62ce43 commit 8628d45
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/test-buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -613,16 +613,27 @@
;;; Spies

(describe "The Spy "
(let (test-function)
(let (saved-test-function saved-test-command)
;; We use `before-all' here because some tests need to access the
;; same function as previous tests in order to work, so overriding
;; the function before each test would invalidate those tests.
(before-all
(setq saved-test-function (and (fboundp 'test-function)
(symbol-function 'test-function))
saved-test-command (and (fboundp 'test-command)
(symbol-function 'test-command)))
(fset 'test-function (lambda (a b)
(+ a b)))
(fset 'test-command (lambda ()
(interactive)
t)))
(after-all
(if saved-test-function
(fset 'test-function saved-test-function)
(fmakunbound 'test-function))
(if saved-test-command
(fset 'test-command saved-test-command)
(fmakunbound 'test-command)))

(describe "`spy-on' function"
(it "replaces a symbol's function slot"
Expand Down

0 comments on commit 8628d45

Please sign in to comment.