I'm using Midje for a project. I've tried to find in the wiki how could I create my own checker, but couldn't find it.
In my case, I want to compare if two images are equal. But it could be that I just want to compare some properties of the file, as it's size, perhaps a couple of pixels. Perhaps the "equality" would be a bit flexible, hence the need of a personalised checker.
How can I do it?
Thanks.
There is a wiki page in midje github repo describing how to define your own checkers.
A checker used on the right hand side of an arrow is a plain predicate function accepting the result of left hand side.
In your example scenario, you can just create your own function for checking a file:
(defn filename-matches? [expected-name]
(fn filename-matcher [actual-file]
(= expected-name (.getAbsolutePath actual-file))))
Then you can use it in your tests:
(generate-file) => (filename-matches? "output.txt")
If you would like use checkers on the left hand side of an arrow you need to follow instructions on another wiki page.
And if you are not satisfied by the format of failure messages generated when using plain predicate functions, you can use some tools described on wiki page discussing chatty checkers.