Dedicated handling of XML declaration nodes.
This commit is contained in:
1 parent
d6c0a1f3f3
commit
bdb76cefc5
7 files changed
+158
-3
No files matched your search
@@ -29,4 +29,21 @@ describe Oga::XML::Document do
|
||||
@document.to_xml.should == '<!--foo-->'
|
||||
end
|
||||
end
|
||||
|
||||
context '#to_xml with XML declarations' do
|
||||
before do
|
||||
decl = Oga::XML::XmlDeclaration.new(:version => '5.0')
|
||||
children = [Oga::XML::Comment.new(:text => 'foo')]
|
||||
|
||||
@document = described_class.new(
|
||||
:xml_declaration => decl,
|
||||
:children => children
|
||||
)
|
||||
end
|
||||
|
||||
example 'include the XML of the declaration tag' do
|
||||
@document.to_xml
|
||||
.should == '<?xml version="5.0" encoding="UTF-8" ?><!--foo-->'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -20,6 +20,33 @@ describe Oga::XML::TreeBuilder do
|
||||
end
|
||||
end
|
||||
|
||||
context '#on_document with XML declarations' do
|
||||
before do
|
||||
decl = s(:xml_decl, s(:attributes, s(:attribute, 'encoding', 'UTF-8')))
|
||||
node = s(:document, decl)
|
||||
@tag = @builder.process(node)
|
||||
end
|
||||
|
||||
example 'set the XML declaration of the document' do
|
||||
@tag.xml_declaration.is_a?(Oga::XML::XmlDeclaration).should == true
|
||||
end
|
||||
end
|
||||
|
||||
context '#on_xml_decl' do
|
||||
before do
|
||||
node = s(:xml_decl, s(:attributes, s(:attribute, 'encoding', 'UTF-8')))
|
||||
@tag = @builder.process(node)
|
||||
end
|
||||
|
||||
example 'return an XmlDeclaration node' do
|
||||
@tag.is_a?(Oga::XML::XmlDeclaration).should == true
|
||||
end
|
||||
|
||||
example 'include the encoding of the tag' do
|
||||
@tag.encoding.should == 'UTF-8'
|
||||
end
|
||||
end
|
||||
|
||||
context '#on_element' do
|
||||
context 'simple elements' do
|
||||
before do
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Oga::XML::XmlDeclaration do
|
||||
context 'setting attributes' do
|
||||
example 'set the version via the constructor' do
|
||||
described_class.new(:version => '1.0').version.should == '1.0'
|
||||
end
|
||||
|
||||
example 'set the version via a setter' do
|
||||
instance = described_class.new
|
||||
instance.version = '1.0'
|
||||
|
||||
instance.version.should == '1.0'
|
||||
end
|
||||
end
|
||||
|
||||
context 'default attribute values' do
|
||||
before do
|
||||
@instance = described_class.new
|
||||
end
|
||||
|
||||
example 'set the default version' do
|
||||
@instance.version.should == '1.0'
|
||||
end
|
||||
|
||||
example 'set the default encoding' do
|
||||
@instance.encoding.should == 'UTF-8'
|
||||
end
|
||||
end
|
||||
|
||||
context '#to_xml' do
|
||||
before do
|
||||
@instance = described_class.new(
|
||||
:version => '1.0',
|
||||
:encoding => 'UTF-8',
|
||||
:standalone => 'yes'
|
||||
)
|
||||
end
|
||||
|
||||
example 'generate the corresponding XML' do
|
||||
@instance.to_xml
|
||||
.should == '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user