nubank / matcher-combinators

Library for creating matcher combinator to compare nested data structures
Other
468 stars 23 forks source link

Allow providing a description to pred matcher #190

Closed philomates closed 1 year ago

philomates commented 1 year ago

addresses https://github.com/nubank/matcher-combinators/issues/145

This is already possible in the PredMatcher defrecord. This change extends it to the pred matcher that calls to PredMatcher.

without a description

(is (match? {:payloads (m/pred pos?)}
            {:payloads -1}))

; FAIL
; expected: (match? {:payloads (m/pred pos?)} {:payloads -1})
;   actual: {:payloads
;  {:expected
;   (pred
;    #object[matcher_combinators.matchers$pred 0xbb81ab9 "matcher_combinators.matchers$pred@bb81ab9"])
;   :actual -1}}

including a description

(is (match? {:payloads (m/pred pos? "positive number")}
            {:payloads -1}))

; FAIL
; expected: (match? {:payloads (m/pred pos? "positive number")} {:payloads -1})
;   actual: {:payloads {:expected "positive number", :actual -1}}
dchelimsky commented 1 year ago

This looks great at first glance, but it makes me think we'd want optional messages for other matchers. WDYT?

philomates commented 1 year ago

it makes me think we'd want optional messages for other matchers

I'd hope that other matchers are mostly self-explanatory from their name + data argument. Can you think of an example where more info is conveyed by also adding in a message?

dchelimsky commented 1 year ago

I can't think of one.

dchelimsky commented 1 year ago

@philomates please add this to the Changelog and then I'll approve/merge.

philomates commented 1 year ago

thanks! updated

dchelimsky commented 1 year ago

Released in 3.8.0: https://clojars.org/nubank/matcher-combinators