Browse files

First pass at human error messages

  • Loading branch information...
1 parent 86afa1e commit f92ab2eafa3c356688cadc3482bf8caec9f8f1a5 @chrismcg committed Jun 11, 2012
Showing with 36 additions and 3 deletions.
  1. +17 −3 lib/yamldiff/yamldiff_error.rb
  2. +19 −0 spec/lib/yamldiff_error_spec.rb
View
20 lib/yamldiff/yamldiff_error.rb
@@ -6,6 +6,20 @@ def initialize(key, context)
end
end
-class YamldiffKeyError < YamldiffError; end
-class YamldiffKeyValueTypeError < YamldiffError; end
-class YamldiffKeyValueError < YamldiffError; end
+class YamldiffKeyError < YamldiffError
+ def to_s
+ "Missing key: #{@key} in path #{@context.join(".")}"
+ end
+end
+
+class YamldiffKeyValueTypeError < YamldiffError
+ def to_s
+ "Key value type mismatch: #{@key} in path #{@context.join(".")}"
+ end
+end
+
+class YamldiffKeyValueError < YamldiffError
+ def to_s
+ "Key value mismatch: #{@key} in path #{@context.join(".")}"
+ end
+end
View
19 spec/lib/yamldiff_error_spec.rb
@@ -0,0 +1,19 @@
+require "spec_helper"
+
+describe YamldiffKeyError, "#to_s" do
+ it "outputs human readable text" do
+ YamldiffKeyError.new('key', ['root', 'namespace']).to_s.should == "Missing key: key in path root.namespace"
+ end
+end
+
+describe YamldiffKeyValueTypeError, "#to_s" do
+ it "outputs human readable text" do
+ YamldiffKeyValueTypeError.new('key', ['root', 'namespace']).to_s.should == "Key value type mismatch: key in path root.namespace"
+ end
+end
+
+describe YamldiffKeyValueError, "#to_s" do
+ it "outputs human readable text" do
+ YamldiffKeyValueError.new('key', ['root', 'namespace']).to_s.should == "Key value mismatch: key in path root.namespace"
+ end
+end

0 comments on commit f92ab2e

Please sign in to comment.