Skip to content

Commit

Permalink
no magic nums, yellow->green for insertions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcoplan committed Jul 17, 2012
1 parent 505db9f commit 477fac1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/rspec/expectations/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/expectations/differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 477fac1

Please sign in to comment.