Checking maps

72 views
Skip to first unread message

Matt Savage

unread,
Feb 11, 2014, 7:43:25 AM2/11/14
to mi...@googlegroups.com
When a map fails a check, I am shown:
  • Actual result
  • The keys that matched expectations
I am really only interested in what didn't match.

Is there a way to see just the check failures?

Brian Marick

unread,
Feb 11, 2014, 9:58:13 PM2/11/14
to mi...@googlegroups.com
No. Mismatch reporting should be done better. I find rspec's style pretty useful.

--------
Latest book: /Functional Programming for the Object-Oriented Programmer/
https://leanpub.com/fp-oo

Korny Sietsma

unread,
Feb 13, 2014, 10:13:59 AM2/13/14
to mi...@googlegroups.com
I would also quite like some way for maps to be ordered when output.  It's definitely just a "nice to have", but on my last project I'd have lots of tests that compared two maps where the output was almost unreadable, as maps are inherently unordered - but when comparing two maps visually, it'd be much easier to scan through them if the keys were (say) alphabetical.

Does that make sense?  Of course if maps were diffed more clearly, this might not matter so much.

On the  subject of mismatch reporting (which I believe Matt just volunteered to fix? :)  I quite like the way Spock provides output of values on an assertion failure:


- Korny


On 12 February 2014 02:58, Brian Marick <mar...@exampler.com> wrote:

On Feb 11, 2014, at 6:43 AM, Matt Savage <matthew...@gmail.com> wrote:

> When a map fails a check, I am shown:
>       * Actual result
>       * The keys that matched expectations

> I am really only interested in what didn't match.
>
> Is there a way to see just the check failures?

No. Mismatch reporting should be done better. I find rspec's style pretty useful.

--------
Latest book: /Functional Programming for the Object-Oriented Programmer/
https://leanpub.com/fp-oo

--
You received this message because you are subscribed to the Google Groups "Midje" group.
To unsubscribe from this group and stop receiving emails from it, send an email to midje+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Kornelis Sietsma  korny at my surname dot com http://korny.info
.fnord { display: none !important; }

Matt Savage

unread,
Feb 13, 2014, 1:19:18 PM2/13/14
to mi...@googlegroups.com
On 13 February 2014 15:13, Korny Sietsma <ko...@sietsma.com> wrote:
...Does that make sense?

Yes. Same.
 
On the  subject of mismatch reporting (which I believe Matt just volunteered to fix? :)  

Dammit Korny :) I believe that is how it works.

Given my commitments at the moment, I suspect someone else will find time before me. But if it's not solved in a couple of months hopefully I'll have a chance to give it a go.


 
I quite like the way Spock provides output of values on an assertion failure:


- Korny


On 12 February 2014 02:58, Brian Marick <mar...@exampler.com> wrote:

On Feb 11, 2014, at 6:43 AM, Matt Savage <matthew...@gmail.com> wrote:

> When a map fails a check, I am shown:
>       * Actual result
>       * The keys that matched expectations
> I am really only interested in what didn't match.
>
> Is there a way to see just the check failures?

No. Mismatch reporting should be done better. I find rspec's style pretty useful.

--------
Latest book: /Functional Programming for the Object-Oriented Programmer/
https://leanpub.com/fp-oo

--
You received this message because you are subscribed to the Google Groups "Midje" group.
To unsubscribe from this group and stop receiving emails from it, send an email to midje+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Kornelis Sietsma  korny at my surname dot com http://korny.info
.fnord { display: none !important; }

--
You received this message because you are subscribed to a topic in the Google Groups "Midje" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/midje/kYsY6d7sUiU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to midje+un...@googlegroups.com.

Rafael de F. Ferreira

unread,
Feb 17, 2014, 2:33:03 PM2/17/14
to mi...@googlegroups.com
Pinpointing the issue in complex datastructures mismatches has been a problem for us, so we built a midje chatty checker to highlight differences. The following code yields the attached screenshot.

       (fact {:a :A :b :B :x :foo} => (embeds {:a :A :b :B
                   :x {:a :A :b :B :y {:k :r}}} ))

It's still experimental, it doesn't support nested checkers, has issues with metaconstants, but I already find it more useful then contains sometimes.




--
Rafael de F. Ferreira.
http://www.rafaelferreira.net/
2014-02-17-162703_954x527_scrot.png

Matt Savage

unread,
Feb 19, 2014, 1:46:38 PM2/19/14
to mi...@googlegroups.com
Rafael- that's really nice. Is it githubbed?

Rafael de F. Ferreira

unread,
Feb 19, 2014, 7:44:47 PM2/19/14
to mi...@googlegroups.com
Thanks, not yet. There are some issues to work through before we release it, like the aforementioned problem with meta constants. Also, it depends on chatty checkers, which AFAIK may be removed from future versions of Midje. Any news on that front?
--

Brian Marick

unread,
Feb 19, 2014, 8:58:26 PM2/19/14
to mi...@googlegroups.com

On Feb 19, 2014, at 6:44 PM, "Rafael de F. Ferreira" <raf...@rafaelferreira.net> wrote:

> Also, it depends on chatty checkers, which AFAIK may be removed from future versions of Midje. Any news on that front?

I love chatty checkers and have no intention of removing them.

Matt Savage

unread,
May 19, 2014, 10:54:16 AM5/19/14
to mi...@googlegroups.com
Follow-up.

Prismatic schema is pretty good at producing validation error messages on large maps.

It's a bit of a hack, but I'm sometimes using this:

(ns test-support 
  (:require [schema.core :as s]
            [clojure.stacktrace :refer [print-cause-trace]]))

(defn is [x]
  (s/pred #(= % x) (str "equal to " x)))

(defn matches [schema & {:keys [loose]}]
  (assert schema "No schema provided")
  (fn [thing]
    (try
      (assert schema "No schema provided")
      (assert thing "Nothing to validate")

      (if-let [errors (s/check (cond-> schema
                                       loose (assoc schema s/Any s/Any)) 
                               thing)]
        (as-data-laden-falsehood {:notes [(with-out-str (pprint errors))]})
        true)

      (catch Exception e
        (as-data-laden-falsehood {:notes [(with-out-str (print-cause-trace e))]})))))

Like this:

{:abc "not an integer"
 :a-list ["one" "two"]}
=> (matches {:abc s/Int
             :a-list [(is "one")
                      (is "two")]})


Only just started exploring the limits of this, but it's suiting me so far. It also avoids a lot of nested contains and just structures for deeply nested assertions, which I sometimes want to make.


--
You received this message because you are subscribed to a topic in the Google Groups "Midje" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/midje/kYsY6d7sUiU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to midje+un...@googlegroups.com.

Matt Savage

unread,
May 19, 2014, 12:10:14 PM5/19/14
to mi...@googlegroups.com
Hmm, reproducing :in-any-order is a pain.

We can use schema coercions and sorting to get a deterministic result though.

{:tags #{:a :c :b}} =>
(matches {:tags (when-sorted (is (sort #{:a :c :b})))})


Expect you could use coercions to reproduce the feasible-permutations stuff in Midje. No time to try right now.

Matt Savage

unread,
May 19, 2014, 1:03:06 PM5/19/14
to mi...@googlegroups.com
Aaand just seen Brian's last post. Same problem, different solution.

Matt Savage

unread,
May 19, 2014, 9:01:10 PM5/19/14
to mi...@googlegroups.com
This does seem to work quite well. Still scrappy and coupled: https://gist.github.com/savagematt/71471bd6619cc0c86910

Implemented a port of the Hamcrest implementation of containsInAnyOrder (so you'll get problems if schemas match more than one element).

Added a coercion to convert non-schema values into equality assertions.

There's an example of a simple transform-and-verify in when-sorted.

The schemas code is grim. There is a test namespace at the bottom of the gist for what would get output in the data laden falsehood.


Reply all
Reply to author
Forward
0 new messages