Skip to content

Commit

Permalink
usable leiningen plugin for midje
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed Oct 24, 2010
1 parent a141371 commit bb7b08d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Expand Up @@ -7,6 +7,7 @@
you at the top level. As with any other identifier used in
code, they must be defined before use. The unfinished macro
is good for that.
* Added a leiningen plugin to get tidy test reports.

= 0.6.1 (stable)
* Midje-mode is (more) compatible with clojure-test-mode.
Expand Down
31 changes: 28 additions & 3 deletions leiningen/midje.clj
@@ -1,5 +1,30 @@
(ns leiningen.midje
(:require [leiningen.test :as lein]))
(:use [leiningen.util.ns :only [namespaces-in-dir]]
[leiningen.compile :only [eval-in-project]]))

(defn midje [project]
(lein/test project))
(defn require-namespaces-form [namespaces]
`(do
(require 'clojure.test)
(alter-var-root (var clojure.test/*report-counters*)
(fn [_#] (ref clojure.test/*initial-report-counters*)))
(doseq [n# '~namespaces] (require n#))
(let [passes# (:pass @clojure.test/*report-counters*)
fails# (:fail @clojure.test/*report-counters*)
failure-message# (condp = fails#
0 (format "All claimed facts (%d) have been confirmed." passes#)
1 (format "FAILURE: %d fact was not confirmed." fails#)
(format "FAILURE: %d facts were not confirmed." fails#))
potential-consolation# (condp = passes#
0 ""
1 "(But 1 was.)"
(format "(But %d were.)" passes#))
consolation# (if (> fails# 0) potential-consolation# "")]
(println failure-message# consolation#))))

(defn midje [project & namespaces]
(let [desired-namespaces (if (empty? namespaces)
(concat (namespaces-in-dir (:test-path project))
(namespaces-in-dir (:source-path project)))
(map symbol namespaces))]
(eval-in-project project
(require-namespaces-form desired-namespaces))))

0 comments on commit bb7b08d

Please sign in to comment.