mardi 22 décembre 2015

with-redefs doesn't redefine my function

I have a test:

    (ns gui-proxy.handler-test
  (:require [clojure.test :refer :all]
            [ring.mock.request :as mock]
            [gui-proxy.handler :as handler]))

(deftest test-app
  (testing "not-found route"
        (with-redefs-fn [handler/log-request  (fn [type url] (str ""))]
          (let [response (handler/app (mock/request :get "/invalid"))]
            (is (= (:status response) 404))))))

and the code that are under test:

(ns gui-proxy.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]
            [clj-http.client :as client]
            [gui-proxy.db :as db]))
(defn log-request [type url]
      (db/insert-request-info type url))

    (defn log-error []
      (log-request ":fail" "fail")
      "gui-proxy - File not found")

    (defroutes app-routes
                   (route/not-found (log-error)))

So, basically i'd like to stop the call to the database-namespace, but i end upp in a fat database exeception stacktrace...

What is wrong?

Aucun commentaire:

Enregistrer un commentaire