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 == '