So, I'm diving deeper and deeper into Clojure.Spec.
One thing I stumbled upon is, where to put my specs. I see three options:
Global Spec File
In most examples, I found online, there is one big spec.clj
file, that gets required in the main namespace. It has all the (s/def)
and (s/fdef)
for all the "data types" and functions.
Pro:
- One file to rule them all
Contra:
- This file can be big
- Single Responsibliy Principle violated?
Specs in production namespaces
You could put your (s/def)
and (s/fdef)
right next to your production code. So that, the implementation and the spec co-exist in the same namespace.
Pro:
- co-location of implementation and spec
- one namespace - one concern?
Contra:
- production code could get messy
- one namespace - two concerns?
Dedicated spec namespace structure
Then I thought, maybe Specs are a third kind of code (next to production and test). So maybe they deserve their own structure of namespaces, like this:
├─ src
│ └─ package
│ ├─ a.clj
│ └─ b.clj
├─ test
│ └─ package
│ ├─ a_test.clj
│ └─ b_test.clj
└─ spec
└─ package
├─ a_spec.clj
└─ b_spec.clj
Pro:
- dedicated (but related) namespaces for specs
Contra:
- you have to source and require the correct namespaces
Who has experience with one of the approaches?
Is there another option?
What do you think about the different options?