unit testing - with-redefs not replacing valid Compojure route function call in clojure.test -


i want test compojure endpoints , see required method called. however, with-redefs-fn not replacing method.

test method-

(ns project-name.handler-test   (:require [clojure.test :refer :all]         [project-name.handler :as handler :refer [retrieve-records test-handler]]         [ring.mock.request :as mock]))  (deftest fn-handler-routes   (with-redefs-fn {#'handler/retrieve-records (fn [arg] :test)}      (let [response {:status 200 :body :test}]      (let [mock-handler (test-handler)]     (is (= response (mock-handler (mock/request :get "/records/name")))))))) 

i guessing routes static, , method fires , returns actual data instead of calling redefined function. test-handler failing attempt try circumvent -- fires okay, not use with-redefs , returns repo data.

pertinent source code-

(defn retrieve-records [arg] (repo/get-records arg))  (defroutes routes   (get "/" [] (resource-response "index.html" {:root "public"}))   (context "/records" []     (get "/name" [] (retrieve-records :lastname)))   (resources "/"))  (defn test-handler []   (-> #'routes wrap-reload)) 

related issues

i suspect similar underlying issue this question midje using clojure.test , not midje.

this question different a similar question in compojure route legitimate , want return in :body, not test status (already tried answer).

this question different an integration test question in handler unit test, though same underlying issue.

any appreciated.


Comments