Tests for the various XML node types.
This commit is contained in:
parent
c366a96ce8
commit
331726b2ca
|
@ -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 == '<![CDATA[foo]]>'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -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 == '<!--foo-->'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -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 == '<!--foo-->'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -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 == '<p></p>'
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'include the namespace if present' do
|
||||||
|
instance = described_class.new(:name => 'p', :namespace => 'foo')
|
||||||
|
|
||||||
|
instance.to_xml.should == '<foo:p></p>'
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'include the attributes if present' do
|
||||||
|
instance = described_class.new(
|
||||||
|
:name => 'p',
|
||||||
|
:attributes => {'key' => 'value'}
|
||||||
|
)
|
||||||
|
|
||||||
|
instance.to_xml.should == '<p key="value"></p>'
|
||||||
|
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 == '<p><!--foo--></p>'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue