Failed prerequisites with wrong args is not printing expected args
Opened this issue · 3 comments
As described in https://github.com/marick/Midje/wiki/Describing-one-checkable%27s-prerequisites, in the case of a failure non equal arguments the, following will print:
FAIL at (NO_SOURCE_FILE:4)
You never said #'g would be called with these arguments:
("hello: world")
Would be nice to print also the expected value, because in the case of equality assertions on some data structures would save some time in figuring out which parts didn't match.
Hello,
Can you post the fact that lead to this output? Also the version of midje you are using / try using the latest (stable) version if you aren't already.
When I run a test like the following, I get the value expected:
(use 'midje.repl)
(unfinished d)
(defn f [] (d 1))
(fact (f) => 2 (provided (d 2) => 2))
FAIL at (form-init6601585616923364043.clj:1)
You never said #'d would be called with these arguments:
[1]
FAIL at (form-init6601585616923364043.clj:1)
These calls were not made the right number of times:
(d 2) [expected at least once, actually never called]
FAIL at (form-init6601585616923364043.clj:1)
Expected:
2
Actual:
"`d` returned this string because it was called with an unexpected argument"
Cheers!
Hi @phillipM,
I am using [midje "1.9.1"]
user=> (use 'midje.repl)
Run `(doc midje)` for Midje usage.
Run `(doc midje-repl)` for descriptions of Midje repl functions.
nil
user=> (unfinished d)
:ok
user=> (defn f [] (d {:time (System/currentTimeMillis)}))
#'user/f
user=> (fact (f) => 2 (provided (d {:time (+ 1 (System/currentTimeMillis))}) => 2))
FAIL at (form-init753595780362288994.clj:1)
You never said #'d would be called with these arguments:
[{:time 1523017468229}]
FAIL at (form-init753595780362288994.clj:1)
These calls were not made the right number of times:
(d {:time (+ 1 (System/currentTimeMillis))}) [expected at least once, actually never called]
FAIL at (form-init753595780362288994.clj:1)
Expected:
2
Actual:
"`d` returned this string because it was called with an unexpected argument"
false
And I think it would be more useful to say:
FAIL at (form-init753595780362288994.clj:1)
You never said #'d would be called with these arguments:
[{:time 1523017468229}]
The expected arguments were:
[{:time 1523017468228}]
This info is currently available in this part of the output
FAIL at (form-init753595780362288994.clj:1)
These calls were not made the right number of times:
(d {:time (+ 1 (System/currentTimeMillis))}) [expected at least once, actually never called]
But it isn't the most readable. Maybe it would be better to reorganize
FAIL at (form-init753595780362288994.clj:1)
You never said #'d would be called with these arguments:
[{:time 1523017468229}]
FAIL at (form-init753595780362288994.clj:1)
These calls were not made the right number of times:
(d {:time (+ 1 (System/currentTimeMillis))}) [expected at least once, actually never called]
to be grouped
You never said #'d would be called with these arguments:
[{:time 1523017468229}]
But #'d was expected to, but was never called with:
(d {:time (+ 1 (System/currentTimeMillis))}) [expected at least once, actually never called]
I like this idea, I will keep it in mind as I work on the failure reporting code (something I have been mucking around in lately). That said, I don't see it being a super straightforward update, so don't hold your breath for it.
Also to keep in mind with this change is that you can add more than one fake for d
(defn f [] (do (d -2) (d -4)))
(fact
(f) => 2
(provided
(d (as-checker pos?)) => 2
(d (as-checker odd?)) => 3))
(see here for as-checker docs)