Permalink
Browse files

no magic nums, yellow->green for insertions

  • Loading branch information...
1 parent 505db9f commit 477fac1a19c374414f7571ddc9776f578605c757 @alexcoplan alexcoplan committed Jul 17, 2012
Showing with 10 additions and 5 deletions.
  1. +9 −4 lib/rspec/expectations/differ.rb
  2. +1 −1 spec/rspec/expectations/differ_spec.rb
@@ -64,19 +64,24 @@ def context_lines
end
def color(text, code)
- "#{code}#{text}\e[0m"
+ "\e[#{code}m#{text}\e[0m"
end
def color_diff(diff)
return diff unless RSpec::Matchers.configuration.color?
+
+ red = 31
+ green = 32
+ blue = 34
+
lines = diff.lines.map do |line|
case line[0]
when "+"
- color(line, "\e[33m") # yellow
+ color(line, green)
when "-"
- color(line, "\e[31m") # red
+ color(line, red)
when "@"
- line[1] == "@" ? color(line, "\e[34m") : line # blue
+ line[1] == "@" ? color(line, blue) : line
else
line
end
@@ -164,7 +164,7 @@ def inspect
it "outputs colored diffs" do
expected = "foo bar baz"
actual = "foo bang baz"
- expected_diff = "\n\e[34m@@ -1,2 +1,2 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[33m+foo bar baz\n\e[0m"
+ expected_diff = "\n\e[34m@@ -1,2 +1,2 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
diff = differ.diff_as_string(expected,actual)

0 comments on commit 477fac1

Please sign in to comment.