Skip to content

Instantly share code, notes, and snippets.

@chrishowejones
Created January 21, 2015 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishowejones/4e8c60e3bcf1573de543 to your computer and use it in GitHub Desktop.
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
(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#)))
@chrishowejones
Copy link
Author

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")
                       (kerodon/follow-redirect)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment