Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to close over Kerodon expressions so they can return truthy/falsey for use with lein-cucumber or deftest
(defmacro wrap-kerodon-test
"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*)]
(defmacro successful-kerodon-expr?
"Return true if the kerodon test function passed as arg runs without reporting a test failure."
`(let [report-counters# (wrap-kerodon-test ~test_func)]
(successful? report-counters#)))

This comment has been minimized.

Copy link
Owner Author

@chrishowejones chrishowejones commented Jan 21, 2015

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:

(successful-kerodon-expr? (-> @session-state (kertest/has (kertest/status? 200))))

Where session-state in this example is an atom that contains the state returned from a Kerodon expression e.g.

(reset! session-state
                   (-> (kerodon/session app)
                       (kerodon/visit "/") 
                       (kerodon/fill-in "Name:" "Chris")
                       (kerodon/press "Create Account")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment