|
3 | 3 | [midje.sweet :refer :all]
|
4 | 4 | [ring.util.http-response :refer [ok]]
|
5 | 5 | [ring.util.http-status :as status]
|
6 |
| - ring.util.test)) |
| 6 | + ring.util.test) |
| 7 | + (:import [java.io PrintStream ByteArrayOutputStream])) |
| 8 | + |
| 9 | +(defmacro without-err |
| 10 | + "Evaluates exprs in a context in which *err* is bound to a fresh |
| 11 | + StringWriter. Returns the string created by any nested printing |
| 12 | + calls." |
| 13 | + [& body] |
| 14 | + `(let [s# (PrintStream. (ByteArrayOutputStream.)) |
| 15 | + err# (System/err)] |
| 16 | + (System/setErr s#) |
| 17 | + (try |
| 18 | + ~@body |
| 19 | + (finally |
| 20 | + (System/setErr err#))))) |
7 | 21 |
|
8 | 22 | (facts serializable?
|
9 | 23 | (tabular
|
|
25 | 39 | (ring.util.test/string-input-stream "foobar") false false))
|
26 | 40 |
|
27 | 41 | (facts "wrap-exceptions"
|
28 |
| - (let [exception (proxy [RuntimeException] [] (printStackTrace [])) |
29 |
| - exception-class (.getName (.getClass exception)) |
30 |
| - failure (fn [_] (throw exception)) |
31 |
| - success (fn [_] (ok "SUCCESS")) |
32 |
| - request irrelevant] |
| 42 | + (with-out-str |
| 43 | + (without-err |
| 44 | + (let [exception (RuntimeException. "kosh") |
| 45 | + exception-class (.getName (.getClass exception)) |
| 46 | + failure (fn [_] (throw exception))] |
33 | 47 |
|
34 |
| - (fact "converts exceptions into safe internal server errors" |
35 |
| - ((wrap-exceptions failure (:handlers (:exceptions api-middleware-defaults))) request) |
36 |
| - => (contains {:status status/internal-server-error |
37 |
| - :body (contains {:class exception-class |
38 |
| - :type "unknown-exception"})})))) |
| 48 | + (fact "converts exceptions into safe internal server errors" |
| 49 | + ((wrap-exceptions failure (:handlers (:exceptions api-middleware-defaults))) ..request..) |
| 50 | + => (contains {:status status/internal-server-error |
| 51 | + :body (contains {:class exception-class |
| 52 | + :type "unknown-exception"})})))))) |
0 commit comments