Skip to content

Instantly share code, notes, and snippets.

@bradlucas
Forked from owainlewis/routes.clj
Created June 18, 2016 13:23
Show Gist options
  • Save bradlucas/bb1e628b4a41ba80f8314c8268225fb6 to your computer and use it in GitHub Desktop.
Save bradlucas/bb1e628b4a41ba80f8314c8268225fb6 to your computer and use it in GitHub Desktop.
Testing Compojure applications in the REPL.
(defroutes app
(GET "/" [] "<h1>Index route</h1>")
(route/not-found "<h1>Page not found</h1>"))
(defn fake-request [routes uri method & params]
(let [localhost "127.0.0.1"]
(routes {:server-port 80
:server-name localhost
:remote-addr localhost
:uri uri
:scheme :http
:headers (or params {})
:request-method method})))
;; YOU CAN TEST ROUTES IN THE REPL
(def index-page (fake-request app "/" :get))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment