lib/minitest/utils/reporter.rb in minitest-utils-0.2.0 vs lib/minitest/utils/reporter.rb in minitest-utils-0.2.1
- old
+ new
@@ -13,10 +13,15 @@
green: 32,
yellow: 33,
blue: 34
}
+ def initialize(*)
+ super
+ @color_enabled = io.respond_to?(:tty?) && io.tty?
+ end
+
def statistics
super
end
def record(result)
@@ -139,11 +144,19 @@
result_code = color(result_code, COLOR_FOR_RESULT_CODE[result_code])
io.print result_code
end
def color(string, color = :default)
- color = COLOR.fetch(color, 0)
- "\e[#{color}m#{string}\e[0m"
+ if color_enabled?
+ color = COLOR.fetch(color, 0)
+ "\e[#{color}m#{string}\e[0m"
+ else
+ string
+ end
+ end
+
+ def color_enabled?
+ @color_enabled
end
def pluralize(word, count)
case count
when 0