Created
November 25, 2012 16:43
-
-
Save thorwil/4144278 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns tlog.dispatch.t-route | |
| (:require [midje.sweet :refer [fact tabular]] | |
| [tlog.dispatch.route :as r] | |
| [tlog.dispatch.handle :as h])) | |
| ;; I would like to do the following for several handlers, later on replacing the fn with one that | |
| ;; returns the handler name and request parameters. | |
| (fact | |
| (with-redefs [h/journal (fn [r] "plop")] | |
| (r/root-routes {:request-method :get :uri "/"})) | |
| => "plop") | |
| ;; But: | |
| (defmacro fact-with-redef-handler | |
| [handler] | |
| `(fact | |
| (with-redefs [~handler (fn [r] "plop")] | |
| (r/root-routes {:request-method :get :uri "/"})) | |
| => "plop")) | |
| (fact-with-redef-handler h/journal) | |
| ;; Leads to: | |
| ;; "CompilerException java.lang.RuntimeException: | |
| ;; Can't use qualified name as parameter: tlog.dispatch.t-route/r" | |
| (for [handler [h/journal h/admin]] | |
| (fact | |
| (with-redefs [handler (fn [r] "plop")] | |
| (r/root-routes {:request-method :get :uri "/"})) | |
| => "plop")) | |
| ;; Leads to: | |
| ;; CompilerException java.lang.RuntimeException: | |
| ;; Unable to resolve var: handler in this context | |
| (for [handler [h/journal h/admin]] | |
| (fact | |
| (with-redefs-fn {handler (fn [r] "plop")} | |
| (fn [] (r/root-routes {:request-method :get :uri "/"}))) | |
| => "plop")) | |
| ;; Leads to: | |
| ;; java.lang.ClassCastException: | |
| ;; tlog.dispatch.handle$journal cannot be cast to clojure.lang.IDeref | |
| ;; java.lang.ClassCastException: | |
| ;; tlog.dispatch.handle$admin cannot be cast to clojure.lang.IDeref | |
| ;; (with-redefs-fn {#'h/journal (fn [r] "plop")} | |
| ;; (fn [] (r/root-routes {:request-method :get :uri "/"}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment