Created
January 21, 2015 14:33
-
-
Save chrishowejones/4e8c60e3bcf1573de543 to your computer and use it in GitHub Desktop.
How to close over Kerodon expressions so they can return truthy/falsey for use with lein-cucumber or deftest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro wrap-kerodon-test | |
[test_func] | |
"Wrap the kerodon test in a binding to that returns the test report counters that can be tested for :pass, :fail, etc." | |
`(binding [clojure.test/*report-counters* (ref clojure.test/*initial-report-counters*)] | |
~test_func | |
@*report-counters*)) | |
(defmacro successful-kerodon-expr? | |
"Return true if the kerodon test function passed as arg runs without reporting a test failure." | |
[test_func] | |
`(let [report-counters# (wrap-kerodon-test ~test_func)] | |
(successful? report-counters#))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The macros here allow you to use Kerodon expressions but get them to return either true or false rather than just writing a report to clojure.test
Usage example:
Where session-state in this example is an atom that contains the state returned from a Kerodon expression e.g.