Fork me on GitHub
#clojure-spec
<
2017-03-13
>
nickik00:03:25

Why can I not say (spec/and (spec/keys :req-un [::id]) (spec/keys :req-un [::old-id]))?

nickik00:03:21

How do I combine two map specs?

nickik00:03:38

That sounds correct.

nickik00:03:45

I did not know this existed

seancorfield00:03:33

There are some examples about a third of the way thru the Guide https://clojure.org/guides/spec

nickik00:03:58

I scrolled threw this multiple times, but I did not see merge

nickik00:03:04

Thank you.

seancorfield00:03:10

(there's only three mentions of merge and it's easy to miss squished in between a couple of big code blocks)

nickik00:03:40

Works like a charm 🙂

nickik00:03:10

If I have something like this: (spec.test/check `my-fn)

nickik00:03:22

Where should I put this so it will be run with other unitests?

nickik00:03:39

Should I just put it like that into the test namespace?

seancorfield00:03:33

You can run the result thru spec.test/summarize (I think) and you can write a deftest around that to assert that the summary shows success.

seancorfield00:03:50

However, one thing to consider is that generative tests are not "fast" like most unit tests should be -- so you might want to think about having a separate task to run generative tests, so that your unit tests stay nice and fast.

nickik00:03:01

Ok. So I have to write a deftest myself. Thats fine given how long it takes to run them.

seancorfield00:03:21

summarize-results -- I had to go look it up.

dpsutton21:03:58

question about tooling: since spec is intextricably linked to 1.9-alphas no tooling can exist for repl's until they are separated. To include spec otherwise would necessarily require hijacking the specified clojure version to 1.9, which would possibly violate people's expectations. Does this sound true and do I have any misconceptions?

dpsutton21:03:29

I'm working on spec tooling in CIDER and I don't know how i could begin without hijacking the clojure version of the project that CIDER is interacting with

ghadi21:03:05

I'm not sure I follow your base assumption. Can tooling check for the existence of spec?

dpsutton21:03:25

well in clojure 1.8, clojure.spec doesn't exist right?

dpsutton21:03:39

ah so it would have to be wrapped in lots of conditional checks?

dpsutton21:03:25

i was just wondering about

(ns nrepl-spec
   (require [clojure.spec :as s])
wouldnt' this throw an error on any clojure < 1.9?

dpsutton21:03:15

1. Unhandled java.io.FileNotFoundException
   Could not locate clojure/spec__init.class or clojure/spec.clj on
   classpath.

ghadi21:03:09

instead check for the existence of a var

ghadi21:03:29

the spec namespace is automatically loaded in clojure 1.9

ghadi21:03:38

that may change, we'll see

dpsutton21:03:48

yeah that makes the problem worse, right?

ghadi21:03:52

(at least when running a clojure repl in 1.9)

ghadi21:03:08

I guess I don't get what the problem is

dpsutton21:03:46

i need middleware to lookup specs to provide a spec browser

ghadi21:03:53

you're gonna need conditionals

dpsutton21:03:58

but if you jack in from a clojure 1.7 project it's gonna blow up

ghadi21:03:11

well yeah the middleware needs to not be dumb

dpsutton21:03:20

when they decouple spec from 1.9 i can just load spec in any clojre 1.7 > which is what cider supports

dpsutton21:03:30

but until then i can't even "talk" about it, i thought

dpsutton21:03:39

like the require statement

ghadi21:03:20

(if (spec-available?)
  (do-cider-stuff)
  :pass)

ghadi21:03:37

a common thing is to try/catch around require

dpsutton21:03:55

i guess that will have to be the case anyways, as I'm sure spec versions will be mismatched

dpsutton22:03:03

thanks for the feedback ghadi

ghadi22:03:05

spec versions?

dpsutton22:03:35

i'm assuming when it's released, CIDER will have clojure.spec 1.8 and someone might be using 1.4? or will it be like clojure.string or set where it's built in

dpsutton22:03:57

i'm not really clear about that

dpsutton22:03:29

didn't know if it's something that will be specified in the project file with a version or if it will be more baked into the language like set and string, etc

ghadi22:03:41

more conditionals

dpsutton22:03:48

haha hooray

ghadi22:03:46

there isn't a guarantee that clojure.spec will be released outside of 1.9 -- it's been mentioned before, but until you see a commit SHA, can't make assumptions

dpsutton22:03:19

i sat next to stuart at dinner at the conj and he said that's what was holding up the release of 1.9. I was going off of that but i understand it's not official

tbaldridge22:03:35

This does bring up a interesting point in the discussion of middleware and nrepl. As long as tools insist on installing new deps into the repl there's going to be problems like this.

dpsutton22:03:50

sorry not stuart but stu

ghadi22:03:57

tooling should degrade gracefully

dpsutton22:03:06

not if i'm writing it

ghadi22:03:15

@tbaldridge you using cider or inf-clojure?

tbaldridge22:03:49

I use Cursive, you insensitive clod 😛

tbaldridge22:03:33

but I do wish all clojure tooling could move away from having middleware in the JVM repl

ghadi22:03:02

what are your reasons for that?

ghadi22:03:11

i can think of several, just curious

tbaldridge22:03:06

it just causes a lot of problems, for no real need. The dependencies used by middleware muck with the resolution order of your repl. Stuff like this spec discussion are due mostly to not being able to use spec in tooling because it might be used in a version of clojure that doesn't support it

tbaldridge22:03:34

and nrepl is too complex for something so simple, lol

tbaldridge22:03:50

all I needed was netcat + a tcp port...and now I have a RPC server inside my program

tbaldridge22:03:08

I guess it's half a rant against middleware and half about nrepl

seancorfield23:03:01

I must admit, I too find it frustrating to need different dependencies in a project based on what a particular editor or other tooling needs. CIDER is great but with the “regular” stack of DEV middleware it takes ages to start an nREPL server. I’ve recently switched to Atom/ProtoREPL and that requires different libraries in play. For non-DEV work, we use the Socker Server but that’s “too light” for useful tooling (unless tooling was rewritten to assume a more neutral Clojure environment and just expected to execute “regular” Clojure over-the-wire).

seancorfield23:03:21

(at the risk of continued a somewhat off-topic discussion!)

ghadi23:03:00

might be off-topic for spec but not in general - being parsimonious about dependencies is very important. gem install hairball applies to our community too

seancorfield23:03:11

If you Bing gem install hairball it brings up this as the top result: https://rubygems.org/gems/hairball/versions/0.1.0 — which in turn links to this: http://www.confreaks.com/videos/860-railsconf2012-keynote-simplicity-matters 😂

seancorfield23:03:58

I assume you knew that was a Rich Hickey reference? 🙂

tbaldridge00:03:29

That's awesome. Although I'm disappointed that it's not a gem that downloads the most recent of every other gem...

ghadi01:03:30

gem install hairball is a quote from simple made easy