spec/explain-data seems very important. It allows programmatic responses to spec failures. Maybe explain-data's behavior hasn't yet stabilized, though? The structure of the return value has changed between 1.9.0-alpha7 to the current 1.9.0-alpha10, the docstring is a bit vague, and the Spec Guide only talks about it very briefly.
At present, it's easy to figure out which test(s) has/have failed by examining the :path value(s) in explain-data's return value in some situations, such as when specs are combined using spec/keys or spec/or. In other situations--at least when specs are combined with spec/and, the:path values are empty. Unlike spec/or, there's no way to specify keywords that would identify the failed test. Am I right that explain-data is in flux? Is the goal that in the future, it will always be possible for developers to specify composite specs in such a way that explain-data can return info that identifies the failed test clearly? For example, in the first spec/and illustration below, maybe explain-data could use the names of the component specs as path elements? (Or am I just confused about something?) Thanks- Example, using Clojure 1.9.0-alpha10: (s/def ::even even?) (s/def ::zero-to-ten (s/int-in 0 10)) ; require number from 0 to 10 inclusive user=> (s/explain-data (s/or :pred1 ::even :pred2 ::zero-to-ten) 11) {:clojure.spec/problems ({:path [:pred1], :pred even?, :val 11, :via [:user/even], :in []} {:path [:pred2], :pred (int-in-range? 0 10 %), :val 11, :via [:user/zero-to-ten], :in []})} ;; Note that the format of the path entries are different above and below. ;; Is there a reason for this difference, or will later versions return ;; the same path elements? user=> (s/explain-data (s/keys :req-un [::even ::zero-to-ten]) {:even 11 :zero-to-ten 11}) {:clojure.spec/problems ({:path [:even], :pred even?, :val 11, :via [:user/even], :in [:even]} {:path [:zero-to-ten], :pred (int-in-range? 0 10 %), :val 11, :via [:user/zero-to-ten], :in [:zero-to-ten]})} ;; Here there's nothing in the :path or :in sequences, although :via provides some information: user=> (s/explain-data (s/and ::even ::zero-to-ten) 11) #:clojure.spec{:problems [{:path [], :pred even?, :val 11, :via [:user/even], :in []}]} ;; Note that only the first failed test is identified, which makes sense. ;; Another s/and example, with no info other than the value of :pred to indicate what test failed: user=> (s/explain-data (s/and even? (s/int-in 0 10)) 11) #:clojure.spec{:problems [{:path [], :pred even?, :val 11, :via [], :in []}]} -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.