Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed prerequisites with wrong args is not printing expected args #439

Open
vfil opened this issue Apr 6, 2018 · 3 comments
Open

Failed prerequisites with wrong args is not printing expected args #439

vfil opened this issue Apr 6, 2018 · 3 comments

Comments

@vfil
Copy link

vfil commented Apr 6, 2018

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.

@philomates
Copy link
Collaborator

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!

@vfil
Copy link
Author

vfil commented Apr 6, 2018

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}]

@philomates
Copy link
Collaborator

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants