From e9412c9c4e84431e4af25b71fb190e694b3aa7f3 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 7 Apr 2014 09:58:31 +0200 Subject: [PATCH] Tests for various inspect methods. --- spec/oga/xml/cdata_spec.rb | 10 ++++++++++ spec/oga/xml/comment_spec.rb | 10 ++++++++++ spec/oga/xml/doctype_spec.rb | 17 +++++++++++++++++ spec/oga/xml/document_spec.rb | 25 +++++++++++++++++++++++++ spec/oga/xml/element_spec.rb | 23 +++++++++++++++++++++++ spec/oga/xml/text_spec.rb | 10 ++++++++++ spec/oga/xml/xml_declaration_spec.rb | 16 ++++++++++++++++ 7 files changed, 111 insertions(+) diff --git a/spec/oga/xml/cdata_spec.rb b/spec/oga/xml/cdata_spec.rb index afe6288..1174f07 100644 --- a/spec/oga/xml/cdata_spec.rb +++ b/spec/oga/xml/cdata_spec.rb @@ -23,4 +23,14 @@ describe Oga::XML::Cdata do @instance.to_xml.should == '' end end + + context '#inspect' do + before do + @instance = described_class.new(:text => 'foo') + end + + example 'pretty-print the node' do + @instance.inspect.should == 'Cdata(text: "foo")' + end + end end diff --git a/spec/oga/xml/comment_spec.rb b/spec/oga/xml/comment_spec.rb index 5dd5008..04d8bf9 100644 --- a/spec/oga/xml/comment_spec.rb +++ b/spec/oga/xml/comment_spec.rb @@ -23,4 +23,14 @@ describe Oga::XML::Comment do @instance.to_xml.should == '' end end + + context '#inspect' do + before do + @instance = described_class.new(:text => 'foo') + end + + example 'pretty-print the node' do + @instance.inspect.should == 'Comment(text: "foo")' + end + end end diff --git a/spec/oga/xml/doctype_spec.rb b/spec/oga/xml/doctype_spec.rb index adaf5a8..ac287e8 100644 --- a/spec/oga/xml/doctype_spec.rb +++ b/spec/oga/xml/doctype_spec.rb @@ -46,4 +46,21 @@ describe Oga::XML::Doctype do instance.to_xml.should == '' end end + + context '#inspect' do + before do + @instance = described_class.new(:name => 'html', :type => 'PUBLIC') + end + + example 'pretty-print the node' do + @instance.inspect.should == <<-EOF.strip +Doctype( + name: "html" + type: "PUBLIC" + public_id: nil + system_id: nil +) + EOF + end + end end diff --git a/spec/oga/xml/document_spec.rb b/spec/oga/xml/document_spec.rb index 34cabaf..a4e7a3b 100644 --- a/spec/oga/xml/document_spec.rb +++ b/spec/oga/xml/document_spec.rb @@ -81,4 +81,29 @@ describe Oga::XML::Document do "\n\n" end end + + context '#inspect' do + before do + @instance = described_class.new( + :doctype => Oga::XML::Doctype.new(:name => 'html'), + :children => [Oga::XML::Comment.new(:text => 'foo')] + ) + end + + example 'pretty-print the node' do + @instance.inspect.should == <<-EOF.strip +Document( + doctype: Doctype( + name: "html" + type: nil + public_id: nil + system_id: nil + ) + xml_declaration: nil + children: [ + Comment(text: "foo") +]) + EOF + end + end end diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb index 7730ff2..c8e326a 100644 --- a/spec/oga/xml/element_spec.rb +++ b/spec/oga/xml/element_spec.rb @@ -57,4 +57,27 @@ describe Oga::XML::Element do instance.to_xml.should == '

' end end + + context '#inspect' do + before do + children = [Oga::XML::Comment.new(:text => 'foo')] + @instance = described_class.new( + :name => 'p', + :children => children, + :attributes => {'class' => 'foo'} + ) + end + + example 'pretty-print the node' do + @instance.inspect.should == <<-EOF.strip +Element( + name: "p" + namespace: nil + attributes: {"class"=>"foo"} + children: [ + Comment(text: "foo") +]) + EOF + end + end end diff --git a/spec/oga/xml/text_spec.rb b/spec/oga/xml/text_spec.rb index 8e8d658..f6d556f 100644 --- a/spec/oga/xml/text_spec.rb +++ b/spec/oga/xml/text_spec.rb @@ -23,4 +23,14 @@ describe Oga::XML::Text do @instance.to_xml.should == 'foo' end end + + context '#inspect' do + before do + @instance = described_class.new(:text => 'foo') + end + + example 'pretty-print the node' do + @instance.inspect.should == 'Text(text: "foo")' + end + end end diff --git a/spec/oga/xml/xml_declaration_spec.rb b/spec/oga/xml/xml_declaration_spec.rb index 6e2f7a7..fb66939 100644 --- a/spec/oga/xml/xml_declaration_spec.rb +++ b/spec/oga/xml/xml_declaration_spec.rb @@ -42,4 +42,20 @@ describe Oga::XML::XmlDeclaration do .should == '' end end + + context '#inspect' do + before do + @instance = described_class.new(:version => '1.0') + end + + example 'pretty-print the node' do + @instance.inspect.should == <<-EOF.strip +XmlDeclaration( + version: "1.0" + encoding: "UTF-8" + standalone: nil +) + EOF + end + end end