I want to write some spec's for a small side project of mine and being worried how to write a spec for a function which does not provide any arguments to pass into it.
I want to write the spec for this particular function:
(defn get-total-pages []
(int (Math/ceil (/ (count (get-posts)) posts-per-page))))
It calculates the total number of pages assuming posts-per-page
posts at one page. The function itself works well, but when adding the following spec to it:
(s/fdef get-total-pages
:args ()
:ret int?)
I can not perform any stest/check
on it without the warning:
:clojure.spec.test.check/ret {:result #error {
:cause "Unable to construct gen at: [] for: clojure.spec.alpha$spec_impl$reify__2059@1232bda3"
...
When not using the :args
mapping it all, spec tell me that :args
is missing, so here my final question: How can I spec a function which do not offer arguments?
The :args
list for a function of no arguments can be spec'd as an empty s/cat
spec:
(s/fdef get-total-pages
:args (s/cat)
:ret int?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With