aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2015-12-23 23:51:21 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2015-12-23 23:51:21 +0100
commit435ebf456984f2e3f051ceef8aa9a1b1f2b918ce (patch)
tree6676ea3a02a818ff74226cd9850a524876b9b2e2
parentaf85e8a987ace926a5d0c21b87a68e2664cfba19 (diff)
downloadrails-435ebf456984f2e3f051ceef8aa9a1b1f2b918ce.tar.gz
rails-435ebf456984f2e3f051ceef8aa9a1b1f2b918ce.tar.bz2
rails-435ebf456984f2e3f051ceef8aa9a1b1f2b918ce.zip
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.
-rw-r--r--railties/lib/rails/test_unit/reporter.rb24
1 files 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