Permalink
Browse files

Support for `lein with-profile foo midje`

  • Loading branch information...
1 parent f1476ea commit 60d154051a897a52bc112db57fd107119dcb477f @marick committed Jan 28, 2013
View
@@ -1,4 +1,4 @@
-(defproject midje "1.5-alpha9"
+(defproject midje "1.5-SNAPSHOT"
:description "A TDD library for Clojure that supports top-down ('mockish') TDD, encourages readable tests, provides a smooth migration path from clojure.test, balances abstraction and concreteness, and strives for graciousness."
:url "https://github.com/marick/Midje"
:dependencies [[org.clojure/clojure "1.4.0"]
@@ -18,12 +18,16 @@
:profiles {:dev {:dependencies [[slamhound "1.2.0"]
[jonase/kibit "0.0.3"]
[jonase/eastwood "0.0.2"]]
- :plugins [[lein-midje "3.0-alpha4"]]}
+ :plugins [[lein-midje "3.0-SNAPSHOT"]]}
:1.2.0 {:dependencies [[org.clojure/clojure "1.2.0"]]}
:1.2.1 {:dependencies [[org.clojure/clojure "1.2.1"]]}
:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
- :1.5 {:dependencies [[org.clojure/clojure "1.5.0-RC1"]]}}
+ :1.5 {:dependencies [[org.clojure/clojure "1.5.0-RC1"]]}
+ ;; The following profile can be used to check that `lein with-profile`
+ ;; profiles are obeyed. Note that profile `:test-paths` *add on* to the
+ ;; defaults.
+ :test-test-paths {:test-paths ["test-test-paths"]}}
:resource-paths ["test-resources"]
:license {:name "The MIT License (MIT)"
:url "http://opensource.org/licenses/mit-license.php"
@@ -13,27 +13,17 @@
(require '[clojure.tools.namespace.repl :as nsrepl]
'[clojure.tools.namespace.dir :as nsdir]
'[clojure.tools.namespace.track :as nstrack]
- '[clojure.tools.namespace.reload :as nsreload]
- '[leiningen.core.project :as project])
+ '[clojure.tools.namespace.reload :as nsreload])
;;; Querying the project tree
- (defn directories []
- (try
- (let [project (project/read)]
- ;; Note that order is important here; see below.
- (concat (:test-paths project) (:source-paths project)))
- (catch java.io.FileNotFoundException e
- ["test"])))
-
(defn namespaces []
- (mapcat namespaces-in-dir (directories)))
+ (mapcat namespaces-in-dir (ecosystem/leiningen-paths)))
- ;; For some purposes, it matters that the :tests files
- ;; come before the :sources files. That happens to always be
- ;; true, but the names below emphasize it.
- (def directories-test-first directories)
+ ;; For some purposes, it matters that the :test-paths files come
+ ;; before the :source-paths files. That happens to always be true,
+ ;; but the name below emphasizes it.
(def namespaces-test-first namespaces)
(defn unglob-partial-namespaces [namespaces]
View
@@ -397,7 +397,7 @@
(defonce ^{:private true}
autotest-options-atom
(atom {:interval 500
- :dirs (project-state/directories)
+ :dirs (ecosystem/leiningen-paths)
:note-require-failure note-require-failure
:note-namespace-stream note-namespace-stream}))
@@ -1,6 +1,7 @@
(ns ^{:doc "Environmental factors."}
midje.util.ecosystem
- (:require [clojure.string :as str]))
+ (:require [clojure.string :as str]
+ [leiningen.core.project :as project]))
(def issues-url "https://github.com/marick/Midje/issues")
@@ -63,3 +64,39 @@
(defn set-config-files! [files]
(alter-var-root #'config-files (constantly files)))
+
+
+;; This is kludgy. We can get the Leiningen profile information
+;; from `lein-midje` if that task sets this atom. There's no way to
+;; get that from `lein repl`, so the default value from `project.clj`
+;; is returned.
+
+(when-1-3+
+
+ (def leiningen-paths-var nil)
+
+ (defmacro around-initial-paths [& body]
+ `(let [original# leiningen-paths-var]
+ (try
+ (alter-var-root #'leiningen-paths-var (constantly nil))
+ ~@body
+ (finally (alter-var-root #'leiningen-paths-var (constantly original#))))))
+
+ (defn set-leiningen-paths! [project]
+ ;; Note that the order is guaranteed: test paths come before project paths.
+ (alter-var-root #'leiningen-paths-var
+ (constantly (concat (:test-paths project) (:source-paths project)))))
+
+ (defn- project-with-paths []
+ (try
+ (project/read)
+ (catch java.io.FileNotFoundException e
+ {:test-paths ["test"]})))
+
+ (defn leiningen-paths []
+ (or leiningen-paths-var
+ (do
+ (set-leiningen-paths! (project-with-paths))
+ leiningen-paths-var)))
+
+)
View
@@ -0,0 +1,2 @@
+This directory is used to check that Midje correctly finds
+alternate test directories.
@@ -0,0 +1,5 @@
+(ns integration.t-pretend
+ (:use midje.sweet))
+
+
+(fact "Look, ma! A failure" 1 => 2)
@@ -9,18 +9,6 @@
(ecosystem/when-1-3+
- (fact "can find paths to load from project.clj"
- (fact "if it exists"
- (directories) => ["/test1" "/src1"]
- (provided (leiningen.core.project/read) => {:test-paths ["/test1"]
- :source-paths ["/src1"]}))
-
- (fact "and provides a default if it does not"
- (directories) => ["test"]
- (provided (leiningen.core.project/read)
- =throws=> (new java.io.FileNotFoundException))))
-
-
(fact "unglob-partial-namespaces returns namespace symbols"
(fact "from symbols or strings"
(unglob-partial-namespaces ["explicit-namespace1"]) => ['explicit-namespace1]
@@ -0,0 +1,27 @@
+(ns midje.util.t-ecosystem
+ (:use midje.sweet
+ midje.util.ecosystem
+ midje.test-util))
+
+(when-1-3+
+
+ (fact "can find paths to load from project.clj"
+ (against-background (around :facts (around-initial-paths ?form)))
+ (fact "if it exists"
+ (leiningen-paths) => ["/test1" "/src1"]
+ (provided (leiningen.core.project/read) => {:test-paths ["/test1"]
+ :source-paths ["/src1"]}))
+
+ (fact "and provides a default if it does not"
+ (leiningen-paths) => ["test"]
+ (provided (leiningen.core.project/read)
+ =throws=> (new java.io.FileNotFoundException)))
+
+ (fact "except that lein-midje can explicitly set the value"
+ (set-leiningen-paths! {:test-paths ["t"] :source-paths ["s"]})
+ (leiningen-paths) => ["t" "s"])
+
+ (fact "note that test paths come first"
+ (set-leiningen-paths! (sorted-map :source-paths ["after"] :test-paths ["before"]))
+ (leiningen-paths) => ["before" "after"]))
+)

0 comments on commit 60d1540

Please sign in to comment.