嗨,我在这里来报告我认为本周第二次出现的 spec 配置项中的怪异现象。
如果这已经作为错误报告过,我深感抱歉,但基本上我无法理解/期望最后的调用会触发错误 - ::id-map
规范并不需要在最后的调用中检查 ::other
。
(ns repro-spec.test
(:require [clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st]))
(s/def ::impl any?)
(s/def ::id string?)
(s/def ::other number?)
(s/def ::id-map (s/keys :req [::id]))
(s/fdef delete-impl
:args (s/cat :impl ::impl
:id-map ::id-map))
(defn delete-impl [_ id-map]
(println (str "This deletes " (::id id-map)))
id-map)
(st/instrument)
(delete-impl {} {::id "test"})
;; prints "This deletes test"
(delete-impl {} {::id "test" ::other "ignore me"})
;; Execution error - invalid arguments to repro-spec.test/delete-impl at (REPL:27).
;; "ignore me" - failed: number? at: [:id-map :repro-spec.test/other] spec: :repro-spec.test/other
我是做错了什么吗?