Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use test-with-files instead of own test helper

  • Loading branch information...
commit c81d1b94cdccca205d7d2fedc5d927290647172a 1 parent 09f8ca7
Magnar Sveen authored
3  project.clj
View
@@ -12,7 +12,8 @@
[org.clojars.elmom/clojure-jna "0.9"]
[net.java.dev.jna/jna "3.5.1"]]
:profiles {:dev {:dependencies [[midje "1.5.0"]
- [optimus-test-jar "0.1.0"]]
+ [optimus-test-jar "0.1.0"]
+ [test-with-files "0.1.0"]]
:plugins [[lein-midje "3.0.0"]
[lein-shell "0.3.0"]]
:resource-paths ["test/resources"]
2  test/optimus/assets_test.clj
View
@@ -1,6 +1,6 @@
(ns optimus.assets-test
(:use [optimus.assets]
- [optimus.test-helper]
+ [test-with-files.core]
[midje.sweet])
(:import java.io.FileNotFoundException))
2  test/optimus/export_test.clj
View
@@ -1,6 +1,6 @@
(ns optimus.export-test
(:require [optimus.export :refer [save-assets]]
- [optimus.test-helper :refer [with-tmp-dir tmp-dir]]
+ [test-with-files.core :refer [with-tmp-dir tmp-dir]]
[clojure.java.io :as io]
[midje.sweet :refer [fact =>]]))
2  test/optimus/optimizations_test.clj
View
@@ -1,7 +1,7 @@
(ns optimus.optimizations-test
(:require [optimus.optimizations :as optimizations]
[optimus.assets]
- [optimus.test-helper :refer [with-files public-dir]]
+ [test-with-files.core :refer [with-files public-dir]]
[clj-time.core :as time])
(:use midje.sweet))
41 test/optimus/test_helper.clj
View
@@ -1,41 +0,0 @@
-(ns optimus.test-helper
- (:require [clojure.java.io :as io]))
-
-(def tmp-dir "test/resources/with-files-tmp")
-
-(def public-dir "with-files-tmp")
-
-(def ^:dynamic *last-modified*)
-
-(defmacro with-tmp-dir [& body]
- `(do
- (.mkdirs (io/file tmp-dir))
- (let [result# (do ~@body)]
- (delete-file-recursively tmp-dir)
- result#)))
-
-(defn app-that-returns-request [request]
- request)
-
-(defn create-file-and-dirs [path contents]
- (let [full-path (str tmp-dir path)]
- (.mkdirs (.getParentFile (io/file full-path)))
- (spit full-path contents)))
-
-(defn delete-file-recursively
- "Delete file f. If it's a directory, recursively delete all its contents.
-Raise an exception if any deletion fails unless silently is true."
- [f & [silently]]
- (let [f (io/file f)]
- (if (.isDirectory f)
- (doseq [child (.listFiles f)]
- (delete-file-recursively child silently)))
- (io/delete-file f silently)))
-
-(defmacro with-files [files & body]
- `(do
- (binding [*last-modified* (* (.intValue (/ (System/currentTimeMillis) 1000)) 1000)]
- (doseq [[path# contents#] ~files] (create-file-and-dirs path# contents#))
- (let [result# (do ~@body)]
- (delete-file-recursively tmp-dir)
- result#))))
Please sign in to comment.
Something went wrong with that request. Please try again.