title: Testing a CRUD Clojure functions like with ruby Rspec
body: <p>I just finished my first six weeks working with Clojure and so far I'm pretty happy with the language. I'm developing my personal blog with leiningen and PostgreSQL. I already can publish new content, upload files and I have sessions, cookies and roles, anyway I think at this point I have enough code to start to worry about the testing section, but I'm kind of stuck since looks like a lot of things are happening in the clojure's testing and spec side. </p>
  
  <p>So I have this function: </p>
  
  <pre><code>(defn download
    "GET /admin/uploads/download/:id"
   [params]
   (let [id       (-&gt; params :id)
         upload   (model-upload/get-upload id)
         filename (:filename upload)
         body     (clojure.java.io/file (str "public/uploads/" filename))]
  {:status 200
   :body body
   :headers {"Content-Type" "application/pdf"
             "Content-Length" (str (.length body))
             "Cache-Control" "no-cache"
             "Content-Disposition" (str "attachment; filename=" filename)}}))
  </code></pre>
  
  <p>The function takes a map as argument and delivers a final map to be sent and processed by compojure. I come from a Rails world so the way to test this function in Rails would be to create a FactoryGirl class, create a Rspec model file with the classic:</p>
  
  <pre><code> expect(first_map).to eq(map_returned_by_function)
  </code></pre>
  
  <p>in it comparing what is expected, and then to run the rspec from the command line to get the green or red line.</p>
  
  <p>Since yesterday I'm trying to replicate that process with Clojure using this doc:</p>
  
  <p><a href="https://www.codesai.com/2018/03/kata-generating-bingo-cards" rel="nofollow noreferrer">https://www.codesai.com/2018/03/kata-generating-bingo-cards</a></p>
  
  <p>but I think there is not yet a "standard" way to do a test including the DB (CRUD) part in Clojure. I don't even know where to put the spec files. I see Clojure libraries similar to FactoryGirl but I don't know if I should create my own data structures with spec so I'm not sure where to start, there are clojure.test.check.generators and spec generators but I don't know if they are different or if I should use only spec but not clojure.test.check. Can I run a test from the command line and not inside the REPL? </p>
  
  <p>I mean: is there a document or tutorial about how to test a set of CRUD functions? I think I just need the initial HOWTO and then I could take it from there and I'll write a tutorial to newbies like me. </p>
  
  <p><strong>UPDATED:</strong></p>
  
  <p>It looks like Midje is what I'm looking for:</p>
  
  <p><a href="https://github.com/marick/Midje/wiki/A-tutorial-introduction" rel="nofollow noreferrer">https://github.com/marick/Midje/wiki/A-tutorial-introduction</a> </p>