Sha256: a6739e54d39eae6840bf2af3744f706204e2133781fe5f7fd033d04615ee286f

Contents?: true

Size: 1.84 KB

Versions: 78

Compression:

Stored size: 1.84 KB

Contents

require "helper"

module Nokogiri
  module XML
    class TestAttr < Nokogiri::TestCase
      def test_new
        assert_nothing_raised do
          100.times {
            doc = Nokogiri::XML::Document.new
            Nokogiri::XML::Attr.new(doc, 'foo')
          }
        end
      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

78 entries across 78 versions & 12 rubygems

Version Path
nokogiri-maglev--1.5.2 test/xml/test_attr.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/test/xml/test_attr.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/test/xml/test_attr.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/test/xml/test_attr.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/test/xml/test_attr.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.2/test/xml/test_attr.rb
ftl-0.2.0 vendor/bundle/gems/nokogiri-1.5.2/test/xml/test_attr.rb
horseman-0.0.5 vendor/ruby/1.9.1/gems/nokogiri-1.5.2/test/xml/test_attr.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/test/xml/test_attr.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/test/xml/test_attr.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/test/xml/test_attr.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/test/xml/test_attr.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/nokogiri-1.5.2/test/xml/test_attr.rb
nokogiri-1.5.3.rc2-java test/xml/test_attr.rb
nokogiri-1.5.3.rc2-x86-mingw32 test/xml/test_attr.rb
nokogiri-1.5.3.rc2-x86-mswin32-60 test/xml/test_attr.rb
nokogiri-1.5.3.rc2 test/xml/test_attr.rb
nokogiri-1.5.2 test/xml/test_attr.rb
nokogiri-1.5.2-x86-mswin32-60 test/xml/test_attr.rb
nokogiri-1.5.2-x86-mingw32 test/xml/test_attr.rb