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」が返されるため、単体テストに合格することを期待していましたが、代わりに、実際の実装が呼び出されるとテストが失敗し、実際のビューが呼び出されます。