Fork me on GitHub
#clojure-spec
<
2017-08-05
>
wilkerlucio00:08:09

@leongrapenthin I think you can do that, you have to give the fspec a name (make a s/def with it), use that name on your usages, then use spec overrides during the run of check, as documented here: https://github.com/clojure/spec.alpha/blob/master/src/main/clojure/clojure/spec/test/alpha.clj#L381

leongrapenthin00:08:06

@wilkerlucio Not sure thats what I'm looking for. My case is like this: A global functions :args are speced like this (s/cat ::config (s/keys :req [::on-click-save])), then there is (s/def ::on-click-save (s/fspec :args (s/cat :cust ::customer)))

leongrapenthin00:08:57

Now when I invoke the global function with {::on-click-save (fn [cust] (persist-on-server cust))}, on-click-save will be invoked a hundred times with generated ::customers by specs validation code

wilkerlucio00:08:26

ah, true, that's for generators

wilkerlucio00:08:08

well, not sure if there is an API for that, but something you could do is to change the spec registry directly, maybe that's a bad idea, but I guess it could work

wilkerlucio00:08:29

its just a map in an atom, nothing fancy

leongrapenthin12:08:06

@wilkerlucio it appears that setting s/fspec-iterations is a workaround, but it disables it for all

leongrapenthin12:08:18

setting it to 0

souenzzo22:08:03

Anyone using spec to specify strings/routes/path/ns? I do not know if it was made for this, but it looks promising

(s/def ::path (s/or :path1 (s/cat :start #{\/}
                                  :name (s/* (s/and char?
                                                    #(not= % \/))))
                    :path2 (s/cat :start #{\/}
                                  :name1 (s/* (s/and char?
                                                     #(not= % \/)))
                                  :div1 #{\/}
                                  :name2 (s/* (s/and char?
                                                     #(not= % \/))))))
=> :user/path
(s/conform ::path (map identity "/foo"))
(s/conform ::path (map identity "/foo/bar"))
=> [:path1 {:start \/, :name [\f \o \o]}]
=> [:path2 {:start \/, :name1 [\f \o \o], :div1 \/, :name2 [\b \a \r]}]

souenzzo22:08:41

Even generators work: (map (partial s/conform ::path) (gen/sample (s/gen ::path)))