2

私はCompojureアプリケーションを作成していて、clj-webdriverそれをグラフィカルにテストするために使用しています。with-redefs永続性からデータを引き出して固定値を返す関数をモックアウトしようとしていますが、関数の上書きを無視しています。varsの観点からは機能することはわかってwith-redefsいますが、まだ機能していません。

project.clj関連の部分:

(defproject run-hub "0.1.0-SNAPSHOT"                                                                                                                        
  :main run-hub.handler/start-server)

handler.clj:

(ns run-hub.handler
  (:require [compojure.core :refer :all]
            [compojure.handler :as handler]
            [compojure.route :as route]
            [ring.adapter.jetty :refer :all]
            [run-hub.controllers.log-controller :as log-controller]))

(defroutes app-routes
  (GET "/MikeDrogalis/log" [] (log-controller/mikes-log))
  (route/resources "/")
  (route/not-found "Not Found"))

(def app (handler/site #'app-routes))

log-controller.clj:

(ns run-hub.controllers.log-controller                                                                                                                      
  (:require [run-hub.views.log :as views]
            [run-hub.persistence :as persistence]))

(defn mikes-log []
  (views/mikes-log (persistence/mikes-log)))

永続性.clj

(ns run-hub.persistence                                                                                                                                     
  (require [clj-time.core :as time]
           [run-hub.models.log :as log]))

(defn mikes-log [] [])

そして最後に、私のグラフィカルテスト-オーバーライドしようとしてmikes-log失敗します:

(fact
 "It has the first date of training as August 19, 2012"
 (with-redefs [persistence/mikes-log (fn [] (one-week-snippet))]
   (to (local "/MikeDrogalis/log"))
   (.contains (text "#training-log") "August 19, 2012"))                                                                                                    
 => true)

one-week-snippetいくつかのサンプルデータを返す関数はどこにありますか。(defn start-server [](run-jetty(var app){:port 3000:join?false}))

4

1 に答える 1

0

with-redefs次のことを行うclj-webdriverテストで使用できます。

(defn with-server
  [f]
  (let [server (run-jetty #'APP {:port 0 :join? false})
        port (-> server .getConnectors first .getLocalPort)]
    (binding [test-port port]
      (try
        (println "Started jetty on port " test-port)
        (f)
        (finally
          (.stop server))))))

(use-fixtures :once with-server)

次に、一連のテスト全体が独自の突堤を取得し、これが機能するように実行されるようですwith-redefs

于 2014-04-02T14:34:04.423 に答える