我正在尝试使用 Midje 在处理程序单元测试中存根视图,但我对 Midje(提供)的使用显然不正确。
我已将视图简化并内联到处理程序中的(内容)函数:
(ns whattodo.handler
(:use compojure.core)
(:require [whattodo.views :as views]))
(defn content [] (views/index))
(defn index [] (content))
(defroutes app
(GET "/" [] (index)))
并尝试使用
(ns whattodo.t-handler
(:use midje.sweet)
(:use ring.mock.request)
(:use whattodo.handler))
(facts "It returns response"
(let [response (app (request :get "/"))]
(fact "renders index view" (:body response) => "fake-html"
(provided (#'whattodo.handler/content) => (fn [] "fake-html")))))
我期待调用存根函数返回'fake-html',因此单元测试通过,但是,测试失败,因为调用了真正的实现 - 调用了真实的视图。