Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor: Explicitly load colour methods.

Don't relying on requiring a file to execute code. Instead provide greater control by making an explicit method which can be called after requiring as seen fit.
  • Loading branch information...
commit 8a5666106c28583f160cd9e34c1b0bcfa3da841c 1 parent b5cc711
Joseph Wilk josephwilk authored
28 src/midje/emission/colorize.clj
View
@@ -10,19 +10,19 @@
(str/upper-case (or (getenv "MIDJE_COLORIZE")
(str (not (on-windows?))))))
-(case (colorize-choice)
- "TRUE" (do
- (def fail color/red)
- (def pass color/green)
- (def note color/cyan))
+(defn init! []
+ (case (colorize-choice)
+ "TRUE" (do
+ (def fail color/red)
+ (def pass color/green)
+ (def note color/cyan))
- "REVERSE" (do
- (def fail color/red-bg)
- (def pass color/green-bg)
- (def note color/cyan-bg))
-
- (do
- (def fail str)
- (def pass str)
- (def note str)))
+ "REVERSE" (do
+ (def fail color/red-bg)
+ (def pass color/green-bg)
+ (def note color/cyan-bg))
+ (do
+ (def fail str)
+ (def pass str)
+ (def note str))))
6 src/midje/util/exceptions.clj
View
@@ -1,9 +1,11 @@
(ns ^{:doc "Functions for Midje to deal elegantly with exceptions."}
midje.util.exceptions
(:use [clojure.string :only [join]]
- [midje.util.ecosystem :only [line-separator]]
- [midje.emission.colorize :only [colorize-choice]]))
+ [midje.util.ecosystem :only [line-separator]])
+ (:require
+ [midje.emission.colorize :as colorize]))
+(colorize/init!)
;;; Creating
7 test/implementation/util/fim_exceptions.clj
View
@@ -1,8 +1,11 @@
(ns implementation.util.fim-exceptions
(:use [midje.util.exceptions]
- [midje.emission.colorize :only [colorize-choice]]
[midje sweet test-util]
- midje.util))
+ [midje.util])
+ (:require
+ [midje.emission.colorize :as colorize))
+
+(colorize/init!)
(expose-testables midje.util.exceptions)
(defrecord R [a])
4 test/midje/emission/t_colorize.clj
View
@@ -6,7 +6,7 @@
(tabular
(fact "wraps string in ascii color when env variable is not explicitly set to FALSE"
(do
- (require '[midje.emission.colorize :as color] :reload ) ;; enables 'provided' to take
+ (color/init!)
(?color-fn "string")) => ?result
(provided
(on-windows?) => ?on-windows :times (range)
@@ -26,7 +26,7 @@
color/note nil true "string")
;; Reset to user's default colorization.
-(require '[midje.emission.colorize] :reload )
+(color/init!)
(fact "access environment vars only when namespace is loaded"
Please sign in to comment.
Something went wrong with that request. Please try again.