在检查范围内覆盖函数规范是有好处的。
例如
(require '[clojure.spec.alpha :as s])
(require '[clojure.spec.test.alpha :as stest])
(defn a [x])
(s/fdef a
:args (s/cat :x int?)
:fn (fn [_] true))
(s/fdef b
:args (s/cat :x int?)
:fn (fn [_] false))
;; 应该通过
(stest/check `a)
(stest/instrument `a {:spec {`a `b}})
;; 应该失败
(stest/check `a)
;; 类似的应该失败的情况
(stest/instrument `a {:spec {`a (s/fspec :args (s/cat :x int?) :fn (fn [_] false))}})
(stest/check `a)
(stest/instrument `a {:spec {`a (s/get-spec `b)}})
(stest/check `a)