lib/konacha/formatter.rb in konacha-3.2.3 vs lib/konacha/formatter.rb in konacha-3.2.4

- old
+ new

@@ -13,21 +13,21 @@ def example_group_started(group); end def example_started(example); end def example_passed(example) @examples << example - io.write(".".green) + io.write(with_color('.', :green)) end def example_failed(example) @examples << example - io.write("F".red) + io.write(with_color('F', :red)) end def example_pending(example) @examples << example - io.write("P".yellow) + io.write(with_color('P', :yellow)) end def example_group_finished(group); end def stop; end @@ -72,9 +72,18 @@ msg << " in #{example.exception.backtrace.first}" if example.exception.backtrace.present? msg.join("\n").red end def pending_message(example) - " Pending: #{example.full_description}".yellow + with_color(" Pending: #{example.full_description}", :yellow) + end + + def color_enabled? + io.tty? + end + + def with_color(text, color) + return text unless color_enabled? + text.colorize(color) end end end