Skip to content
This repository
Browse code

Merge pull request #169 from alexcoplan/better_diff_coloring

Better diff coloring
  • Loading branch information...
commit f4d4cd00ea755f02328fb36f00918e8d147b9ad3 2 parents d427bac + 7cdd88b
Myron Marston authored
31  lib/rspec/expectations/differ.rb
@@ -63,30 +63,37 @@ def context_lines
63 63
         3
64 64
       end
65 65
 
66  
-      def color(text, code)
67  
-        "\e[#{code}m#{text}\e[0m"
  66
+      def color(text, color_code)
  67
+        "\e[#{color_code}m#{text}\e[0m"
  68
+      end
  69
+
  70
+      def red(text)
  71
+        color(text, 31)
  72
+      end
  73
+
  74
+      def green(text)
  75
+        color(text, 32)
  76
+      end
  77
+
  78
+      def blue(text)
  79
+        color(text, 34)
68 80
       end
69 81
 
70 82
       def color_diff(diff)
71 83
         return diff unless RSpec::Matchers.configuration.color?
72 84
 
73  
-        red = 31
74  
-        green = 32
75  
-        blue = 34
76  
-
77  
-        lines = diff.lines.map do |line|
  85
+        diff.lines.map { |line|
78 86
           case line[0].chr
79 87
           when "+"
80  
-            color(line, green)
  88
+            green line
81 89
           when "-"
82  
-            color(line, red)
  90
+            red line
83 91
           when "@"
84  
-            line[1].chr == "@" ? color(line, blue) : line
  92
+            line[1].chr == "@" ? blue(line) : line
85 93
           else
86 94
             line
87 95
           end
88  
-        end
89  
-        lines.join
  96
+        }.join
90 97
       end
91 98
 
92 99
       def object_to_string(object)
2  lib/rspec/matchers/configuration.rb
@@ -43,7 +43,7 @@ def syntax
43 43
       # fallback if rspec core not available
44 44
       if defined?(RSpec::Core)
45 45
         def color?
46  
-          RSpec.configuration.color
  46
+          RSpec.configuration.color_enabled?
47 47
         end
48 48
       else
49 49
         attr_writer :color

0 notes on commit f4d4cd0

Please sign in to comment.
Something went wrong with that request. Please try again.