From 8899542971f348c58e83d8a920864326aea7ba31 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 1 Aug 2014 19:00:47 +0200 Subject: [PATCH] Better specs for Document#each_node. --- spec/oga/xml/document_spec.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/spec/oga/xml/document_spec.rb b/spec/oga/xml/document_spec.rb index 9dba917..cd2a3f0 100644 --- a/spec/oga/xml/document_spec.rb +++ b/spec/oga/xml/document_spec.rb @@ -30,6 +30,39 @@ describe Oga::XML::Document do end end + context '#each_node' do + before do + @document = parse(<<-EOF.strip.gsub(/\s+/m, '')) + + + Foo + + + Bar + + + 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')