在specs alpha 2中,如果我们定义一个 clojure.alpha.spec/select
,它是作为嵌套spec定义的 s/schema
,而嵌套spec本身又是一个 s/schema
(但使用未命名空间键),并且尝试使用它与 s/valid?
或 s/exercise
结合使用,我们会得到异常
s/valid
抛出 *"No implementation of method: :conform of protocol: '#'clojure.alpha.spec.protocols/Spec found for class: clojure.lang.Keyword" error,而 s/exercise
抛出 "Unable to resolve spec: :foo"** (其中 :foo
是未命名空间键) 错误。
以下是一个示例,可以更好地说明问题
; Context
(s/def ::foo int?)
(s/def ::inner (s/schema [{:foo ::foo}]))
(s/def ::outer (s/schema [::inner]))
; Works as expected:
(s/exercise ::outer)
(s/exercise (s/select ::inner [*]))
(s/valid? (s/select ::inner [*]) {:foo 10})
; Fails with "Unable to resolve spec: :foo"
(s/exercise (s/select ::outer [*]))
; Fails with "No implementation of method: :conform* of protocol: #'clojure.alpha.spec.protocols/Spec found for class: clojure.lang.Keyword"
(s/valid? (s/select ::outer [*]) {::inner {:foo 10}})