Sha256: 31ba9b252d7e88e976c81878d66f8c2a2d913c24321591a730e1fb75a1782fbd

Contents?: true

Size: 1.18 KB

Versions: 48

Compression:

Stored size: 1.18 KB

Contents

require 'rubygems'
require 'active_support'
require "test/unit"

require File.dirname(__FILE__) + "/../lib/xml_node"

class TestXmlNode < Test::Unit::TestCase
  
  def test_parse_sanity    
    assert_raise(ArgumentError) { XmlNode.parse }
    assert_nothing_raised { XmlNode.parse('<feed/>') }
  end


  def test_parse_attributes
    node = XmlNode.parse('<feed attr="1"/>')
    assert_equal '1', node['attr']
    assert_equal nil, node['attr2']
  end
  
  def test_parse_children
    node = XmlNode.parse('<feed><element>text</element></feed>')
    assert_equal XmlNode, node.children['element'].class
    assert_equal 'text', node.children['element'].text
  end
  
  def test_enumerate_children
    count = 0
    XmlNode.parse('<feed><element>text</element><element>text</element></feed>').children.each { count += 1 }
    assert_equal 2, count
  end

  def test_find_first
    xml = XmlNode.parse('<feed><elem>1</elem><elem>2</elem><elem>3</elem></feed>')
    assert_equal '1', xml.find(:first, '//elem').text
  end

  def test_find_all
    xml = XmlNode.parse('<feed><elem>1</elem><elem>2</elem><elem>3</elem></feed>')
    assert_equal ['1', '2', '3'], xml.find(:all, '//elem').collect(&:text)
  end

end

Version data entries

48 entries across 48 versions & 6 rubygems

Version Path
omniship-0.3.2.2 lib/vendor/xml_node/test/test_parsing.rb
omniship-0.1.0 lib/vendor/xml_node/test/test_parsing.rb
kschadeck-active_shipping-0.9.15 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.14 lib/vendor/xml_node/test/test_parsing.rb
rclements_active_shipping-0.9.15 lib/vendor/xml_node/test/test_parsing.rb
rclements_active_shipping-0.9.14 lib/vendor/xml_node/test/test_parsing.rb
rclements_active_shipping-0.9.13 lib/vendor/xml_node/test/test_parsing.rb
benhutton-active_shipping-0.9.13 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.13 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.12 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.11 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.10 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.9 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.8 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.7 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.6 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.5 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.4 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.3 lib/vendor/xml_node/test/test_parsing.rb
active_shipping-0.9.2 lib/vendor/xml_node/test/test_parsing.rb