aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin--handle-fetch-callback.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-21 08:31:24 -0400
committerCraig Jennings <c@cjennings.net>2026-06-21 08:31:24 -0400
commit55c60f025e834c6bc60523542644ac0ec03d035c (patch)
treef8bce1933679fd46674996ef7da6a6ce68fb2f1e /tests/test-wttrin--handle-fetch-callback.el
parent021b5bb771bff834bc67d82fa61b870e175bdf71 (diff)
downloademacs-wttrin-55c60f025e834c6bc60523542644ac0ec03d035c.tar.gz
emacs-wttrin-55c60f025e834c6bc60523542644ac0ec03d035c.zip
test: extract message-capture helper into testutil
Five test files hand-rolled the same scaffolding to capture the echo-area message: a nil-initialized var, a cl-letf on message, and a lambda that stored the formatted string. Centralize it as testutil-wttrin-with-captured-message, which binds the var and captures the last message shown. Behavior is unchanged. The full suite stays green. Sites that mock message for a different reason are left alone: the ones that silence it with #'ignore, and the one that accumulates every message into a list.
Diffstat (limited to 'tests/test-wttrin--handle-fetch-callback.el')
-rw-r--r--tests/test-wttrin--handle-fetch-callback.el21
1 files changed, 6 insertions, 15 deletions
diff --git a/tests/test-wttrin--handle-fetch-callback.el b/tests/test-wttrin--handle-fetch-callback.el
index d4158ac..e50c61d 100644
--- a/tests/test-wttrin--handle-fetch-callback.el
+++ b/tests/test-wttrin--handle-fetch-callback.el
@@ -226,12 +226,9 @@
(ert-deftest test-wttrin--handle-fetch-callback-error-network-shows-message ()
"Network errors should show a specific message in the echo area,
not leave the user guessing."
- (let ((displayed-message nil))
+ (testutil-wttrin-with-captured-message displayed-message
(cl-letf (((symbol-function 'wttrin--extract-response-body)
- (lambda () nil))
- ((symbol-function 'message)
- (lambda (fmt &rest args)
- (setq displayed-message (apply #'format fmt args)))))
+ (lambda () nil)))
(wttrin--handle-fetch-callback
'(:error (error "Network unreachable"))
#'ignore)
@@ -240,14 +237,11 @@ not leave the user guessing."
(ert-deftest test-wttrin--handle-fetch-callback-error-http-404-shows-message ()
"HTTP 404 should tell the user the location wasn't found."
- (let ((displayed-message nil))
+ (testutil-wttrin-with-captured-message displayed-message
(cl-letf (((symbol-function 'wttrin--extract-response-body)
(lambda () nil))
((symbol-function 'wttrin--extract-http-status)
- (lambda () 404))
- ((symbol-function 'message)
- (lambda (fmt &rest args)
- (setq displayed-message (apply #'format fmt args)))))
+ (lambda () 404)))
;; No :error in status — url-retrieve succeeded but server returned 404
(wttrin--handle-fetch-callback nil #'ignore)
(should displayed-message)
@@ -255,14 +249,11 @@ not leave the user guessing."
(ert-deftest test-wttrin--handle-fetch-callback-error-http-500-shows-message ()
"HTTP 500 should tell the user the weather service had an error."
- (let ((displayed-message nil))
+ (testutil-wttrin-with-captured-message displayed-message
(cl-letf (((symbol-function 'wttrin--extract-response-body)
(lambda () nil))
((symbol-function 'wttrin--extract-http-status)
- (lambda () 500))
- ((symbol-function 'message)
- (lambda (fmt &rest args)
- (setq displayed-message (apply #'format fmt args)))))
+ (lambda () 500)))
(wttrin--handle-fetch-callback nil #'ignore)
(should displayed-message)
(should (string-match-p "service\\|server\\|500" (downcase displayed-message))))))