Fork me on GitHub
#testing
<
2022-10-07
>
zeddan07:10:35

I’m trying to write a fixture:

;; test-helper.clj
(defn db-reset-fixture [fn]
  (reset-db)
  (with-redefs [cnf/order (fn [] {:jdbcUrl "db-url"})] ;; <---- This is where the error occurs
    (fn))
  (cleanup-db))
;; the test
(ns robins-test
  (:require [clojure.test :refer :all]
            [order-service.config :as cnf]
            [test-helper]))

(use-fixtures :each test-helper/db-reset-fixture)

(deftest abc
  (testing "abc"
    (println "test")))
This gives me the error:`Exception: clojure.lang.ArityException: Wrong number of args (2) passed to: robins-test/fn--3878` Are there any hidden assumtpions that I’m missing? I’m using the (with-redefs [cnf/whatever (fn [] {:a "b"})]) pattern in other places successfully so I can’t figure out what is happening

zeddan07:10:13

Oh I see it now! Of course I can’t use the reserved keyword fn as the argument for the fixture

seancorfield07:10:34

t is more idiomatic in a fixture since it is a test (function).

zeddan07:10:18

I will use t then, thanks!

seancorfield07:10:19

Also, fn is not a "reserved keyword" -- the error occurs because you are shadowing a core symbol, so (fn [] ..) calls the fn passed as an argument to your fixture function -- and what is passed is a niladic function (no arguments).