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

0 votes
in Spec by

(s/def :fspec-test/plus (s/fspec
                         :args (s/cat :x int? :y pos-int?)
                         :ret pos-int?))

(defn my-plus [x y]
  (+ x y))

(s/explain-data :fspec-test/plus my-plus)

;; #:clojure.spec.alpha{:problems [{:path [:ret], :pred clojure.core/pos-int?, :val 0, :via [:fspec-test/plus], :in []}], :spec :fspec-test/plus, :value #function[expound.alpha-test/my-plus]}

Expected: There should be some way to get the spec (i.e. the function itself, not a symbol) that fails for the return value. That way, we can recursively describe why the return value fails the spec.

Note that for a non-fspec failure, the function itself (not the symbol) is included in the explain-data:

(s/explain-data pos-int? 0)

;; #:clojure.spec.alpha{:problems [{:path [], :pred :clojure.spec.alpha/unknown, :val 0, :via [], :in []}], :spec #function[clojure.core/pos-int?], :value 0}

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-2256 (reported by bbrinck)