Better specs for Document#each_node.

This commit is contained in:
Yorick Peterse 2014-08-01 19:00:47 +02:00
parent c419d8849b
commit 8899542971
1 changed files with 33 additions and 0 deletions

View File

@ -30,6 +30,39 @@ describe Oga::XML::Document do
end
end
context '#each_node' do
before do
@document = parse(<<-EOF.strip.gsub(/\s+/m, ''))
<books>
<book>
<title>Foo</title>
</book>
<book>
<title>Bar</title>
</book>
</books>
EOF
end
example 'yield the nodes in document order' do
names = []
@document.each_node do |node|
names << (node.is_a?(Oga::XML::Element) ? node.name : node.text)
end
names.should == %w{books book title Foo book title Bar}
end
example 'yield the document indexes' do
indexes = []
@document.each_node { |_, index| indexes << index }
indexes.should == [0, 1, 2, 3, 4, 5, 6]
end
end
context '#to_xml' do
before do
child = Oga::XML::Comment.new(:text => 'foo')