Sha256: 4d34d956b0c6f4fd67455c36ec4a8e279587b4dbd554cc9679382bc14f340b1d
Contents?: true
Size: 1.81 KB
Versions: 181
Compression:
Stored size: 1.81 KB
Contents
require "helper" module Nokogiri module XML class TestAttr < Nokogiri::TestCase def test_new 100.times { doc = Nokogiri::XML::Document.new assert doc assert Nokogiri::XML::Attr.new(doc, 'foo') } end def test_content= xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) address = xml.xpath('//address')[3] street = address.attributes['street'] street.content = "Y&ent1;" assert_equal "Y&ent1;", street.value end def test_value= xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) address = xml.xpath('//address')[3] street = address.attributes['street'] street.value = "Y&ent1;" assert_equal "Y&ent1;", street.value end def test_unlink xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) address = xml.xpath('/staff/employee/address').first assert_equal 'Yes', address['domestic'] address.attribute_nodes.first.unlink assert_nil address['domestic'] end def test_parsing_attribute_namespace doc = Nokogiri::XML <<-EOXML <root xmlns='http://google.com/' xmlns:f='http://flavorjon.es/'> <div f:myattr='foo'></div> </root> EOXML node = doc.at_css "div" attr = node.attributes["myattr"] assert_equal "http://flavorjon.es/", attr.namespace.href end def test_setting_attribute_namespace doc = Nokogiri::XML <<-EOXML <root xmlns='http://google.com/' xmlns:f='http://flavorjon.es/'> <div f:myattr='foo'></div> </root> EOXML node = doc.at_css "div" attr = node.attributes["myattr"] attr.add_namespace("fizzle", "http://fizzle.com/") assert_equal "http://fizzle.com/", attr.namespace.href end end end end
Version data entries
181 entries across 181 versions & 12 rubygems