Skip to content

Commit

Permalink
Fixed attribute parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerhunt committed Aug 31, 2009
1 parent 870dfca commit 463c788
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/relief/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def xpath
else
attribute = @options[:attribute]
attribute = name if attribute == true
!attribute ? "#{name}/text()" : "@#{attribute}"
!attribute ? "#{name}/text()" : ".//@#{attribute}"
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions spec/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.join(File.dirname(__FILE__), 'spec_helper')

describe Relief::Parser do
it "returns nil if the document can't be parsed" do
it "raises a ParseError if the document can't be parsed" do
parser = Relief::Parser.new(:photo) do
element :name
element :url
Expand Down Expand Up @@ -61,6 +61,8 @@

it "parses attributes" do
parser = Relief::Parser.new(:photos) do
attribute :status

elements :photo do
attribute :name
attribute :url
Expand All @@ -69,13 +71,14 @@

photos = parser.parse(<<-XML)
<?xml version="1.0" encoding="UTF-8"?>
<photos>
<photos status="fine">
<photo name="Cucumbers" url="/photos/cucumbers.jpg" />
<photo name="Lemons" url="/photos/lemons.jpg" />
</photos>
XML

photos.should == {
:status => 'fine',
:photo => [
{ :name => 'Cucumbers', :url => '/photos/cucumbers.jpg' },
{ :name => 'Lemons', :url => '/photos/lemons.jpg' }
Expand Down

0 comments on commit 463c788

Please sign in to comment.