From 331726b2cac5161f74c7db638f2442cc0800297f Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 28 Mar 2014 16:34:30 +0100 Subject: [PATCH] Tests for the various XML node types. --- spec/oga/xml/cdata_spec.rb | 26 +++++++++++++++ spec/oga/xml/comment_spec.rb | 26 +++++++++++++++ spec/oga/xml/document_spec.rb | 32 +++++++++++++++++++ spec/oga/xml/element_spec.rb | 60 +++++++++++++++++++++++++++++++++++ spec/oga/xml/node_spec.rb | 16 ++++++++++ spec/oga/xml/text_spec.rb | 26 +++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 spec/oga/xml/cdata_spec.rb create mode 100644 spec/oga/xml/comment_spec.rb create mode 100644 spec/oga/xml/document_spec.rb create mode 100644 spec/oga/xml/element_spec.rb create mode 100644 spec/oga/xml/node_spec.rb create mode 100644 spec/oga/xml/text_spec.rb diff --git a/spec/oga/xml/cdata_spec.rb b/spec/oga/xml/cdata_spec.rb new file mode 100644 index 0000000..afe6288 --- /dev/null +++ b/spec/oga/xml/cdata_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Oga::XML::Cdata do + context 'setting attributes' do + example 'set the text via the constructor' do + described_class.new(:text => 'foo').text.should == 'foo' + end + + example 'set the text via a setter' do + instance = described_class.new + instance.text = 'foo' + + instance.text.should == 'foo' + end + end + + context '#to_xml' do + before do + @instance = described_class.new(:text => 'foo') + end + + example 'generate the corresponding XML' do + @instance.to_xml.should == '' + end + end +end diff --git a/spec/oga/xml/comment_spec.rb b/spec/oga/xml/comment_spec.rb new file mode 100644 index 0000000..5dd5008 --- /dev/null +++ b/spec/oga/xml/comment_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Oga::XML::Comment do + context 'setting attributes' do + example 'set the text via the constructor' do + described_class.new(:text => 'foo').text.should == 'foo' + end + + example 'set the text via a setter' do + instance = described_class.new + instance.text = 'foo' + + instance.text.should == 'foo' + end + end + + context '#to_xml' do + before do + @instance = described_class.new(:text => 'foo') + end + + example 'generate the corresponding XML' do + @instance.to_xml.should == '' + end + end +end diff --git a/spec/oga/xml/document_spec.rb b/spec/oga/xml/document_spec.rb new file mode 100644 index 0000000..7a5632f --- /dev/null +++ b/spec/oga/xml/document_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe Oga::XML::Document do + context 'setting attributes' do + example 'set the child nodes via the constructor' do + children = [Oga::XML::Comment.new(:text => 'foo')] + document = described_class.new(:children => children) + + document.children.should == children + end + + example 'set the child nodes via a setter' do + children = [Oga::XML::Comment.new(:text => 'foo')] + document = described_class.new + + document.children = children + + document.children.should == children + end + end + + context '#to_xml' do + before do + child = Oga::XML::Comment.new(:text => 'foo') + @document = described_class.new(:children => [child]) + end + + example 'generate the corresponding XML' do + @document.to_xml.should == '' + end + end +end diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb new file mode 100644 index 0000000..7730ff2 --- /dev/null +++ b/spec/oga/xml/element_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe Oga::XML::Element do + context 'setting attributes' do + example 'set the name via the constructor' do + described_class.new(:name => 'p').name.should == 'p' + end + + example 'set the name via a setter' do + instance = described_class.new + instance.name = 'p' + + instance.name.should == 'p' + end + + example 'set the default attributes' do + described_class.new.attributes.should == {} + end + end + + context '#attribute' do + before do + @instance = described_class.new(:attributes => {'key' => 'value'}) + end + + example 'return an attribute' do + @instance.attribute('key').should == 'value' + end + end + + context '#to_xml' do + example 'generate the corresponding XML' do + described_class.new(:name => 'p').to_xml.should == '

' + end + + example 'include the namespace if present' do + instance = described_class.new(:name => 'p', :namespace => 'foo') + + instance.to_xml.should == '

' + end + + example 'include the attributes if present' do + instance = described_class.new( + :name => 'p', + :attributes => {'key' => 'value'} + ) + + instance.to_xml.should == '

' + end + + example 'include the child nodes if present' do + instance = described_class.new( + :name => 'p', + :children => [Oga::XML::Comment.new(:text => 'foo')] + ) + + instance.to_xml.should == '

' + end + end +end diff --git a/spec/oga/xml/node_spec.rb b/spec/oga/xml/node_spec.rb new file mode 100644 index 0000000..3502303 --- /dev/null +++ b/spec/oga/xml/node_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe Oga::XML::Node do + context '#initialize' do + example 'set the parent node' do + parent = described_class.new + child = described_class.new(:parent => parent) + + child.parent.should == parent + end + + example 'set the default child nodes' do + described_class.new.children.should == [] + end + end +end diff --git a/spec/oga/xml/text_spec.rb b/spec/oga/xml/text_spec.rb new file mode 100644 index 0000000..8e8d658 --- /dev/null +++ b/spec/oga/xml/text_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Oga::XML::Text do + context 'setting attributes' do + example 'set the text via the constructor' do + described_class.new(:text => 'foo').text.should == 'foo' + end + + example 'set the text via a setter' do + instance = described_class.new + instance.text = 'foo' + + instance.text.should == 'foo' + end + end + + context '#to_xml' do + before do + @instance = described_class.new(:text => 'foo') + end + + example 'generate the corresponding XML' do + @instance.to_xml.should == 'foo' + end + end +end