Permalink
Browse files

fixed coloring, added tests for colored diff

  • Loading branch information...
1 parent dbe5aa3 commit 54b9e980a8974512e974513d801d96fd647420d6 @alexcoplan committed Jul 17, 2012
Showing with 28 additions and 2 deletions.
  1. +1 −1 lib/rspec/expectations/differ.rb
  2. +10 −0 lib/rspec/matchers/configuration.rb
  3. +17 −1 spec/rspec/expectations/differ_spec.rb
@@ -63,7 +63,7 @@ def context_lines
3
end
- def color(code, text)
+ def color(text, code)
"#{code}#{text}\e[0m"
end
@@ -39,7 +39,17 @@ def syntax
syntaxes
end
+ # Some methods for color config in Expectations.
+ # Expectations should be independent from Core, therefore
+ # color should fallback to being configurable here, if core
+ # is not available.
+ #
+ # Tests to see if --color is available within expectations
+ # should be made here
if defined?(RSpec::Core)
+ def color=(bool)
+ RSpec.configuration.color = bool
+ end
def color?
RSpec.configuration.color
end
@@ -6,8 +6,9 @@ module Expectations
describe Differ do
context "without --color" do
+ before { RSpec::Matchers.configuration.color = false }
+
let(:differ) { RSpec::Expectations::Differ.new }
- before { RSpec.configuration.color = false }
# color disabled context
@@ -155,6 +156,21 @@ def inspect
end
end # end context
+ context "with --color" do
+ before { RSpec::Matchers.configuration.color = true }
+
+ let(:differ) { RSpec::Expectations::Differ.new }
+
+ it "outputs coloured 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"
+
+
+ diff = differ.diff_as_string(expected,actual)
+ diff.should == expected_diff
+ end
+ end
end
end

0 comments on commit 54b9e98

Please sign in to comment.