This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-07
Channels
- # announcements (2)
- # babashka (34)
- # beginners (114)
- # biff (7)
- # calva (16)
- # cider (2)
- # clj-kondo (46)
- # clj-on-windows (14)
- # clojars (13)
- # clojure (33)
- # clojure-europe (17)
- # clojure-nl (2)
- # clojure-norway (8)
- # clojure-spec (3)
- # clojure-uk (3)
- # clojurescript (25)
- # community-development (1)
- # datalevin (1)
- # emacs (53)
- # fulcro (31)
- # gratitude (2)
- # jobs (1)
- # lambdaisland (12)
- # lsp (57)
- # malli (3)
- # nbb (1)
- # off-topic (92)
- # pathom (2)
- # pedestal (2)
- # releases (5)
- # shadow-cljs (25)
- # sql (3)
- # squint (1)
- # testing (6)
- # vim (11)
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).
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).