From 55c60f025e834c6bc60523542644ac0ec03d035c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 21 Jun 2026 08:31:24 -0400 Subject: 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. --- tests/test-wttrin--handle-fetch-callback.el | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'tests/test-wttrin--handle-fetch-callback.el') 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)))))) -- cgit v1.2.3