testing

zeddan 2022-10-07T07:36:35.854139Z

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

zeddan 2022-10-07T07:39:13.147569Z

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

seancorfield 2022-10-07T07:45:34.480259Z

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

zeddan 2022-10-07T07:46:18.171719Z

I will use t then, thanks!

seancorfield 2022-10-07T07:47:19.812369Z

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).

zeddan 2022-10-07T07:47:55.052649Z

Check