From 94f7f85dc3a778c2d5762ade23e0b26babda4a55 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 8 Jul 2015 01:26:58 +0200 Subject: [PATCH] Added XML::Document#root_node --- lib/oga/xml/document.rb | 12 ++++++++++++ spec/oga/xml/document_spec.rb | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/oga/xml/document.rb b/lib/oga/xml/document.rb index 55792d4..e5d4a36 100644 --- a/lib/oga/xml/document.rb +++ b/lib/oga/xml/document.rb @@ -54,6 +54,18 @@ module Oga end end + ## + # Returns self. + # + # This method exists to make this class compatible with Element, which in + # turn makes it easier to use both in the XPath compiler. + # + # @return [Oga::XML::Document] + # + def root_node + self + end + ## # Converts the document and its child nodes to XML. # diff --git a/spec/oga/xml/document_spec.rb b/spec/oga/xml/document_spec.rb index 29ac158..119d600 100644 --- a/spec/oga/xml/document_spec.rb +++ b/spec/oga/xml/document_spec.rb @@ -34,6 +34,14 @@ describe Oga::XML::Document do end end + describe '#root_node' do + it 'returns self' do + doc = described_class.new + + doc.root_node.should == doc + end + end + describe '#to_xml' do before do child = Oga::XML::Comment.new(:text => 'foo')