Skip to content

Commit

Permalink
test: Do not leak functions from "The Spy " test suite
Browse files Browse the repository at this point in the history
The (symbol-function test-function) cannot be lexically bound, but
equivalent behaviour can be acheived using before-all and after-all.
  • Loading branch information
snogge committed Sep 26, 2019
1 parent 9d172a7 commit e62ce43
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 e62ce43

Please sign in to comment.