Skip to content

Commit

Permalink
Improve fail message for the :to-have-been-called-times matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
snogge committed Dec 8, 2023
1 parent b18ab7f commit f2f7f81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,9 @@ UNEVALUATED-EXPR if it did not raise any signal."
(let* ((call-count (spy-calls-count spy)))
(cond
((= number call-count)
t)
(cons t
(format "Expected `%s' to not have been called exactly %s %s, but it was."
spy number (if (= number 1) "time" "times"))))
(t
(cons nil
(format "Expected `%s' to have been called %s %s, but it was called %s %s"
Expand Down
12 changes: 8 additions & 4 deletions tests/test-buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,14 @@ text properties using `ansi-color-apply'."
(expect (buttercup--apply-matcher
:to-have-been-called-times
(mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 6)))
:to-be-truthy))
:to-equal
'(t . "Expected `i-spy-with-my-little-eye' to not have been called exactly 6 times, but it was.")))
(it "should match if the spy has been called 0 times"
(expect (buttercup--apply-matcher
:to-have-been-called-times
(mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 0)))
:to-be-truthy))))
:to-equal
'(t . "Expected `i-spy-with-my-little-eye' to not have been called exactly 0 times, but it was.")))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Suite and spec data structures
Expand Down Expand Up @@ -1453,7 +1455,8 @@ text properties using `ansi-color-apply'."
(expect (buttercup--apply-matcher
:to-have-been-called-times
(mapcar #'buttercup--wrap-expr '('test-function 2)))
:to-equal t))
:to-equal
(cons t "Expected `test-function' to not have been called exactly 2 times, but it was.")))

(it "use plural words in error message"
(test-function)
Expand Down Expand Up @@ -1591,7 +1594,8 @@ text properties using `ansi-color-apply'."
(expect (buttercup--apply-matcher
:to-have-been-called-times
(mapcar #'buttercup--wrap-expr '('test-function-throws-on-negative 2)))
:to-equal t))
:to-equal
'(t . "Expected `test-function-throws-on-negative' to not have been called exactly 2 times, but it was.")))

(it "records args to the function whether it throw an error or not"
(test-function-throws-on-negative 5)
Expand Down

0 comments on commit f2f7f81

Please sign in to comment.