Fork me on GitHub
#clojure-spec
<
2016-11-03
>
Alex Miller (Clojure team)05:11:28

@potetm feel free, although I don’t know that there is much need :)

Alex Miller (Clojure team)05:11:33

@jasonjckn backwards compatible changes do not necessarily require a new spec (for example, s/keys will always validate all registered keys, so adding new ones does not require a spec change)

Alex Miller (Clojure team)05:11:03

@jasonjckn breaking changes should mean a new spec

Alex Miller (Clojure team)05:11:06

I expect this area will receive more attention as its something Rich has thought about a lot

Alex Miller (Clojure team)05:11:03

and he’s really serious about not just “changing” specs but actually leaving the existing one and creating a new one (::person2, ::person3, etc)

jrheard05:11:16

the evils of “using the same name to refer to different things"

ikitommi05:11:53

has anyone managed to do the “take a spec, walk it and transform it to another (differently conforming) spec”? I tried, but for s/keys it seems hard/impossible. Have already copied much of the clojure.spec internals into my project for this. With un-keys, it’s easy, with the non-un keys, it’s not: the key names should remain same, with a different implementation.

ikitommi05:11:52

would be nice, if there was a map-kind of Spec in clojure.spec that would allow separate keys and values - I could just swap the values in this case. Could there be such a thing under the hoods of s/keys @alexmiller?

gfredericks18:11:30

@ikitommi having a consistent meaning for a namespaced keyword is one of the core ideas of clojure.spec

zane18:11:20

ikitommi's question relates to my earlier one about whether conformed values are more or less intended to remain internal to the function in which they were conformed.

zane18:11:26

When used idiomatically, anyway.

ikitommi19:11:18

@gfredericks true that, but for external input, there is a need to conform/coerce values differently, based on capabilities of the wire format. Stuarts thought was to transform raw specs into new specs, with different conformers.

zane19:11:17

How would that preclude you from using different keys for the new specs, ikitommi?

ikitommi19:11:01

what if I want to expose a fully-qualified key?

ikitommi19:11:32

for unqualified keys, I can just create a new spec key, e.g. :mydomain/age => :JSON.mydomain/age, as both can be mapped to the use the :age key.

kuzmin_m19:11:03

Hi! I play with spec and found one dangerous point. I use s/fspec to specify high-order function foo with bar argument. In several cases I may call foo with bar that have some side effects. When instrument is enabled then bar will be called more than onсе because spec will check bar. For instance I may write smth like that: (foo delete-user-by-id) and debug it many hours. I can check only bar arity but stest/check will not work.

(ns spec.func.example
  (:require [clojure.spec :as s]
            [clojure.spec.test :as stest]))

(defn foo [bar]
  (bar 42))

(s/def ::bar (s/fspec :args (s/cat :x integer?)
                      :ret integer?))

(s/fdef foo
  :args (s/cat :bar ::bar)
  :ret integer?)

(stest/instrument)

(foo #(do
        (println %) ;; print more than once !!!
        (inc %)))

drewr19:11:31

@kuzmin_m I've been dealing with exactly this

drewr19:11:16

you might not want to use check at all, but instrument with its :replace option, and then call the function normally

kuzmin_m19:11:57

Yes. But people are careless. If something is breakable it’ll be broken.

kuzmin_m20:11:02

I may forget specify replace option

drewr20:11:06

not sure what you mean

kuzmin_m20:11:59

I need an extraordinary action. I need remember about s/fspec behaviour and specify instrument option.

kuzmin_m20:11:23

May we write a function that replace s/fspec by fn? when we use instrument? We don’t call fn and we only check an argument type in this case.

bfabry20:11:52

@kuzmin_m that would make instrument significantly less useful

bfabry20:11:11

fwiw, I think there should probably be more explicit handling of functions with side-effects for both fspec and fdef, and I'm hopeful that something is coming

kuzmin_m20:11:11

Sure! But it only about fspec, not about fdef.

bfabry20:11:09

they're kinda the same thing though, fdef as far as I understand it is just (s/def name (s/fspec blah))

kuzmin_m20:11:17

Yes. I just write about one case: s/fspec for function argument.

bfabry20:11:28

right, I just mentioned fdef because you can use the name of something fdef'd somewhere in place of an fspec and you'll get the same behaviour. but anyway you're right that it would be on fspec where things need to be handled

kuzmin_m20:11:22

right 👍 I forget about that behavior 😞

kuzmin_m20:11:01

It’s just alpha version. I hope that we can fix this issue.

mrcnc21:11:16

is there a “best practices” way to run spec tests from lein?

jrheard23:11:08

i haven’t seen official guidance on the one true specifically correct invocation of clojure.spec.test/check, but when i dig around in github search i usually see people write clojure.test assertions like (is (= 0 ((summarize-results foo) :failures))) or whatever

jrheard23:11:16

handwaving here, but you get the idea

kenny23:11:41

It works well with Cursive’s run tests REPL action

kenny23:11:20

Example usage:

(t/defspec-test st-test-name `you-function-to-test)