diff --git a/lib/oga/xml/element.rb b/lib/oga/xml/element.rb index cde3ff9..8980fc2 100644 --- a/lib/oga/xml/element.rb +++ b/lib/oga/xml/element.rb @@ -211,11 +211,9 @@ module Oga attrs = '' attributes.each do |attr| - attrs << attr.to_xml + attrs << " #{attr.to_xml}" end - attrs = " #{attrs}" unless attrs.empty? - return "<#{ns}#{name}#{attrs}>#{body}" end diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb index 047c606..88d8716 100644 --- a/spec/oga/xml/element_spec.rb +++ b/spec/oga/xml/element_spec.rb @@ -261,7 +261,7 @@ describe Oga::XML::Element do instance.to_xml.should == '' end - example 'include the attributes if present' do + example 'include a single attribute if present' do instance = described_class.new( :name => 'p', :attributes => [ @@ -272,6 +272,18 @@ describe Oga::XML::Element do instance.to_xml.should == '

' end + example 'include multiple attributes if present' do + instance = described_class.new( + :name => 'p', + :attributes => [ + Oga::XML::Attribute.new(:name => 'key1', :value => 'value1'), + Oga::XML::Attribute.new(:name => 'key2', :value => 'value2'), + ] + ) + + instance.to_xml.should == '

' + end + example 'include the child nodes if present' do instance = described_class.new( :name => 'p',