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 happeningOh I see it now! Of course I can’t use the reserved keyword fn as the argument for the fixture
t is more idiomatic in a fixture since it is a test (function).
I will use t then, thanks!
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).
Check