From 435ebf456984f2e3f051ceef8aa9a1b1f2b918ce Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Wed, 23 Dec 2015 23:51:21 +0100 Subject: Move test coloring closer to where it's used. Didn't like the constant being at the top of the file, gave it overdue importance. Now that `color_output` expects a result we can shorten some of the flexibility from earlier: * Inline COLOR_CODES constant (keep local variable for readability, but don't need names of colors at run time). * Inline color variable in `color_output`. Looks just as clear without it. --- railties/lib/rails/test_unit/reporter.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb index 17dfb8bcea..73b8d7d27b 100644 --- a/railties/lib/rails/test_unit/reporter.rb +++ b/railties/lib/rails/test_unit/reporter.rb @@ -6,19 +6,6 @@ module Rails class_attribute :executable self.executable = "bin/rails test" - COLOR_CODES_FOR_RESULTS = { - "." => :green, - "E" => :red, - "F" => :red, - "S" => :yellow - } - - COLOR_CODES = { - red: 31, - green: 32, - yellow: 33 - } - def record(result) super @@ -104,10 +91,17 @@ module Rails options[:color] && io.respond_to?(:tty?) && io.tty? end + codes = { red: 31, green: 32, yellow: 33 } + COLOR_BY_RESULT_CODE = { + "." => codes[:green], + "E" => codes[:red], + "F" => codes[:red], + "S" => codes[:yellow] + } + def color_output(string, by:) if colored_output? - color = COLOR_CODES_FOR_RESULTS[by.result_code] - "\e[#{COLOR_CODES[color]}m#{string}\e[0m" + "\e[#{COLOR_BY_RESULT_CODE[by.result_code]}m#{string}\e[0m" else string end -- cgit v1.2.3