Fork me on GitHub
#clojure-spec
<
2016-10-12
>
jmglov08:10:05

Is it possible to spec functions defined in a protocol?

jmglov08:10:26

Or the implementations thereof in a defrecord or reify?

hiredman08:10:40

you can fdef a protocol function, and you'll be able to validate it, but instrument may behave oddly

danielstockton08:10:36

I found instrument doesn't work, I make my protocol functions a simple proxy to another function that I can spec

wotbrew10:10:38

Has anyone had any success spec'ing high level components, such as ring handlers? I would like to spec boundaries rather than implementation details in an app I'm working on and it seems like this will be a ton of work.

jmglov11:10:30

@danielstockton That's what I'm doing for now. It would be really nice if instrument worked, though. 🙂

jmglov11:10:55

@alexmiller Is that something worth submitting as a feature request? Or is unlikely to be considered?

jmglov11:10:39

@hiredman So I can do something like this?

(defprotocol Foo
  (bar [this]))

(s/fdef bar
        :args (s/cat :x int?
                     :y int?)
        :ret string?)

(defrecord MyFoo [_]
  Foo
  (bar [_] (str a "+" b))

alexmiller13:10:59

I'm not sure it's possible to do

alexmiller13:10:18

I'm certainly not opposed to it

jfntn14:10:02

Is there a working equivalent of (s/map-of ::k ::v :kind sorted?) for sorted maps?

alexmiller15:10:18

There is sorted-map? predicate

alexmiller15:10:39

I think? On phone so going from memory

jfntn15:10:59

Hmm I don’t think so, at least in alpha12?

clojuregeek16:10:59

Trying to use spec, and have a problem with setting up my spec ... basically i want style? to be one of those two values (for now :one :two) ... but it is not working, i've been studying the docs and i can't figure out where i am doing something wrong .

jrheard16:10:27

@clojuregeek - i think you want to either do (def style? #{:one :two}) and (s/def ::style style?), or just (s/def ::style #{:one :two})

jrheard16:10:58

i don’t think (s/def) expects you to give it a symbol like style? as the first argument, i think it expects a namespaced keyword like ::style

jrheard16:10:24

also you have ::style?? in there at one point, which is probably confusing things as well

bfabry16:10:36

yes, you've registered the spec under the symbol style? instead of under the keyword ::style?

clojuregeek16:10:03

ok let me try some more ..

clojuregeek17:10:27

ok i think maybe it was extra ? on style in job not a keyword when i defined style? spec

clojuregeek17:10:31

thanks guys 👍

clojuregeek17:10:27

now if i can only stop typing confirm instead of conform 🙂