branch: elpa/buttercup commit 0f3eb636c220ab4b822d309d7a0f6817e0fb9229 Author: Jorgen Schaefer <cont...@jorgenschaefer.de> Commit: Jorgen Schaefer <cont...@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)