Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Test by

How can I use this feature to check that a function is valid given

2 Answers

+6 votes
by

It helps to define a helper function, something like:

(defn speccheck [fn-to-check options]
  (let [results (t/check [fn-to-check] options)]
    (if (some :failure results)
      (do
        (println "\nFailed specs:")
        (doseq [result results
               :when (:failure result)]
          (println (:sym result))
          (pprint (or (ex-data (:failure result))
                      (:failure result)))))
      true)))

(deftest my-fun-test
  (is (speccheck `this/is-my-fn {}))) ; pass options to t/check as needed

This helps in the failure case because you want the failures printed.

by
thanks I'm gonna give it a try
0 votes
by

You can also use expound for reporting:

(defn is*
  [results]
  (assert (seq results))
  (test/is
   (if (some :failure results)
     (exp/explain-results results)
     true)))

Usage:

(is* (stest/check `ns/fn))

Note: assert will fail if there is no spec for that function.

...