emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/buttercup 0f3eb63 078/340: Show actual function arguments


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup 0f3eb63 078/340: Show actual function arguments when a spy fails.
Date: Thu, 16 Dec 2021 14:59:07 -0500 (EST)

branch: elpa/buttercup
commit 0f3eb636c220ab4b822d309d7a0f6817e0fb9229
Author: Jorgen Schaefer <contact@jorgenschaefer.de>
Commit: Jorgen Schaefer <contact@jorgenschaefer.de>

    Show actual function arguments when a spy fails.
    
    It's not very helpful to be told that a spy was not called with the
    expected arguments without being told what it actually was being
    called with.
    
    Fixes #19
---
 buttercup.el            | 18 +++++++++++++++---
 tests/test-buttercup.el | 10 ++++++----
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/buttercup.el b/buttercup.el
index 9a67d2d..f9f0a44 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -565,9 +565,21 @@ KEYWORD can have one of the following values:
 
 (buttercup-define-matcher :to-have-been-called-with (spy &rest args)
   (let* ((calls (mapcar 'spy-context-args (spy-calls-all spy))))
-    (if (member args calls)
-        t
-      nil)))
+    (cond
+     ((not calls)
+      (cons nil
+            (format "Expected `%s' to have been called with %s, but it was not 
called at all" spy args)))
+     ((not (member args calls))
+      (cons nil
+            (format "Expected `%s' to have been called with %s, but it was 
called with %s"
+                    spy
+                    args
+                    (mapconcat (lambda (args)
+                                 (format "%S" args))
+                               calls
+                               ", "))))
+     (t
+      t))))
 
 (defun spy-calls-any (spy)
   "Return t iff SPY has been called at all, nil otherwise."
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index 8cc48d8..5df1952 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -499,15 +499,17 @@
       (it "returns false if the spy was not called at all"
         (expect (buttercup--apply-matcher
                  :to-have-been-called-with '(test-function 1 2 3))
-                :to-be
-                nil))
+                :to-equal
+                (cons nil
+                      "Expected `test-function' to have been called with (1 2 
3), but it was not called at all")))
 
       (it "returns false if the spy was called with different arguments"
         (test-function 3 2 1)
         (expect (buttercup--apply-matcher
                  :to-have-been-called-with '(test-function 1 2 3))
-                :to-be
-                nil))
+                :to-equal
+                (cons nil
+                      "Expected `test-function' to have been called with (1 2 
3), but it was called with (3 2 1)")))
 
       (it "returns true if the spy was called with those arguments"
         (test-function 1 2 3)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]