spec/niceogiri/xml/node_spec.rb in niceogiri-1.0.2 vs spec/niceogiri/xml/node_spec.rb in niceogiri-1.1.0

- old
+ new

@@ -44,10 +44,18 @@ subject[:bar].should be_nil subject.write_attr :bar, 'baz' subject[:bar].should == 'baz' end + it 'provides an attribute writer with conversion' do + subject[:bar].should be_nil + subject.write_attr :bar, '1.0', :to_i + subject[:bar].should == '1' + subject.write_attr :bar, nil, :to_i + subject[:bar].should == nil + end + it 'provides a content reader' do foo = Node.new 'foo' foo << (bar = Node.new('bar', foo.document)) bar.content = 'baz' foo.read_content(:bar).should == 'baz' @@ -137,13 +145,22 @@ n['foo'].should == 'bar' n.content.should == 'bar' n2.to_s.should == n.to_s end - it 'holds on to namespaces when inheriting content' do + it 'holds on to namespace prefixes when inheriting content' do n = Nokogiri::XML.parse('<message><bar:foo xmlns:bar="http://bar.com"></message>').root n2 = Node.new('message').inherit n n2.to_s.should == n.to_s + end + + it 'holds on to namespaces when inheriting content' do + n = Nokogiri::XML.parse('<message xmlns="foobar"><body xmlns="barfoo"/></message>').root + n2 = Node.new('message').inherit n + n2.to_s.should == n.to_s + n2.namespace.href.should be == 'foobar' + body = n2.children.first + body.namespace.href.should be == 'barfoo' end it 'holds on to namespaces without a prefix when inheriting content' do n = Nokogiri::XML.parse('<message><bar:foo xmlns="http://bar.com"></message>').root n2 = Node.new('message').inherit n