【发布时间】:2015-04-16 04:47:05
【问题描述】:
我正在尝试使用 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”,从而通过单元测试,但是,测试失败,因为调用了真正的实现 - 调用了真正的视图。
【问题讨论】:
标签: unit-testing clojure ring compojure midje