Permalink
Browse files

Add Diffy and get ready for using it

  • Loading branch information...
1 parent f92ab2e commit 8c64a334b8cbd600c5a2ae81a96f8677659a069d @chrismcg committed Jun 11, 2012
Showing with 26 additions and 1 deletion.
  1. +1 −0 lib/yamldiff.rb
  2. +12 −1 lib/yamldiff/yamldiff_error.rb
  3. +12 −0 spec/lib/yamldiff_error_spec.rb
  4. +1 −0 yamldiff.gemspec
View
@@ -1,4 +1,5 @@
require 'yaml'
+require 'diffy'
require "yamldiff/version"
require "yamldiff/yamldiff_error"
require "yamldiff/yamldiff"
@@ -19,7 +19,18 @@ def to_s
end
class YamldiffKeyValueError < YamldiffError
+ def initialize(key, context, diff = nil)
+ super key, context
+ @diff = diff
+ end
+
def to_s
- "Key value mismatch: #{@key} in path #{@context.join(".")}"
+ output = []
+ output << "Key value mismatch: #{@key} in path #{@context.join(".")}"
+ if @diff
+ output << "Diff:"
+ output << @diff
+ end
+ output.join("\n")
end
end
@@ -16,4 +16,16 @@
it "outputs human readable text" do
YamldiffKeyValueError.new('key', ['root', 'namespace']).to_s.should == "Key value mismatch: key in path root.namespace"
end
+
+ it "outputs diff if given" do
+ str1 = "foo\n"
+ str2 = "bar\n"
+ diff = Diffy::Diff.new(str1, str2)
+ YamldiffKeyValueError.new('key', ['root', 'namespace'], diff).to_s.should == <<-OUTPUT
+Key value mismatch: key in path root.namespace
+Diff:
+-foo
++bar
+OUTPUT
+ end
end
View
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
gem.name = "yamldiff"
gem.require_paths = ["lib"]
gem.version = Yamldiff::VERSION
+ gem.add_dependency 'diffy'
gem.add_development_dependency 'fakefs'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'

0 comments on commit 8c64a33

Please sign in to comment.