Fork me on GitHub
Chris Reyes01:05:36

I’m interested in using spec (for the first time) for a side project I’m working on. Where should I put the spec definitions? (Or is that a controversial question?)

Chris Reyes01:05:33

I found this But I’m not sure they came to a consensus in any of the answers/comments. (Or maybe I’m not sure how to interpret it because I’m still pretty new to spec)


@chrisreyes Most people tend to put data specs in their own namespace, possibly with a few utilities for processing that data, but put function specs next to (above) the functions to which they apply.


If you want specs to be "optional" for some functions, it makes sense to put them in a separate namespace, so that users can decide whether to load them or not.

Chris Reyes01:05:53

Okay, thanks!


There is no "right way" or "wrong way" -- whatever is most convenient/makes the most sense.


When I added function specs to next.jdbc recently, I put them all in a separate namespace, so users could choose whether to use them or not


That ns actually contains fdefs for two other namespaces within the next.jdbc project, just because that was the most natural/convenient way to set things up.


But having fdefs separate isn't as common as having s/defs for data separate.


Part of the issue is that specs can serve a lot of different purposes. They can be used for testing in several ways. They can be used to support development (`st/instrument` for example). They can be used in production for data validation (and other things).


What's & rest in spec. I want to spec [:a :B :C :D] and make sure that first is :a and the rest can by of any amount of any type? (s/cat :need-a ::need-a (&rest?))


(s/cat :need-a ::need-a :rest (s/* any?))


the nested s/* (and other regex ops) is flattened out by default so that doesn't mean [:a [:b ...]]


ahh I see 🙂 thanks dj! Still after 2 years of spec, these basics are still troubling me


that one definitely requires "grokking"


yes I would have expected a nested sequence for that


I guess with a lisp hat on you would expect it to nest, but if you were trying to imagine expressing regex via s-expressions it would look like that too so 🤷

👍 4

s/tuple behaves how you might expect iirc


Do people do generative testing over side-effectful code and/or integration tests? I feel it is nice to be able to put an fdef spec over an API endpoint on a webserver (e.g. required params and possible responses) but am unconvinced setting up the check as it starts becoming a bit like a super verbose example test. I suppose instrument with :stub option could work but I'm trying to find a nice way of tying fdefs into integration tests...

Jakub Holý (HolyJak)09:05:00

Speaking about integration / system tests, these talks, and Datomic Simulat could be of interest. Regarding side-effects, I guess it depends on their kind. Some you certainly want to avoid when testing. (x with datmoic, you can use an "in-memory" local copy of the DB and never "commit" / transact into the original DB yet have everything there for verification.


thanks for sharing


will take a look!


alas we're not using Datomic at work though