Permalink
Browse files

Updated to raise Relief::ParseError on errors.

  • Loading branch information...
1 parent ec15c01 commit 870dfca5703fa0402057cf393eb2ce6d56d33fa1 @tylerhunt committed May 28, 2009
Showing with 17 additions and 0 deletions.
  1. +1 −0 CHANGELOG
  2. +5 −0 lib/relief/parser.rb
  3. +11 −0 spec/parser_spec.rb
View
@@ -1,6 +1,7 @@
0.0.4 - Current
* Added support for type casting (Tyler Hunt)
+* Updated to raise Relief::ParseError on parse errors (Tyler Hunt)
0.0.3 - May 7, 2009
View
@@ -2,6 +2,9 @@
require 'nokogiri'
module Relief
+ class Error < StandardError ; end
+ class ParseError < Error ; end
+
class Parser
attr_reader :root
@@ -15,6 +18,8 @@ def parse(document)
end
@root.parse(document)
+ rescue Nokogiri::XML::XPath::SyntaxError
+ raise ParseError
end
end
end
View
@@ -1,6 +1,17 @@
require File.join(File.dirname(__FILE__), 'spec_helper')
describe Relief::Parser do
+ it "returns nil if the document can't be parsed" do
+ parser = Relief::Parser.new(:photo) do
+ element :name
+ element :url
+ end
+
+ lambda {
+ parser.parse('')
+ }.should raise_error(Relief::ParseError)
+ end
+
it "parses elements" do
parser = Relief::Parser.new(:photo) do
element :name

0 comments on commit 870dfca

Please sign in to comment.