class TestXmlNode

Public Instance Methods

test_add_array_of_nodes() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 70
def test_add_array_of_nodes
  assert_equal '<feed><e>1</e><e>2</e><e>3</e></feed>', XmlNode.new('feed') { |n| n << [1,2,3].collect{ |i| XmlNode.new('e', i) }}.to_s    
end
test_attributes() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 48
def test_attributes
  node = XmlNode.new('feed')
  node['attr'] = 1
  assert_equal '1', node['attr']
end
test_boolean() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 74
def test_boolean
  assert_equal '<boolean>true</boolean>', XmlNode.new('boolean', true).to_s
  assert_equal '<boolean>false</boolean>', XmlNode.new('boolean', false).to_s
end
test_cdata() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 29
def test_cdata
  node = XmlNode.new('feed')
  node.text = '...'
  node.cdata = 'Goodbye world'
  node.cdata = 'Hello world'
  
  assert_equal '<feed>...<![CDATA[Hello world]]></feed>', node.to_s
  assert_equal 'Hello world', node.cdata
  assert_equal '...', node.text
end
test_dont_choke_on_nil_pushing() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 84
def test_dont_choke_on_nil_pushing    
  feed = XmlNode.new 'feed'    
  assert_nothing_raised do 
    feed << nil
  end
  assert_equal '<feed/>', feed.to_s
end
test_element_generation() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 17
def test_element_generation    
  assert_equal '<feed/>', XmlNode.new('feed').to_s
  assert_equal '<feed>content</feed>', XmlNode.new('feed', 'content').to_s
  assert_equal "<feed attr='true'>content</feed>", XmlNode.new('feed', 'content', :attr => true).to_s
  assert_equal "<feed attr='true'/>", XmlNode.new('feed', :attr => true).to_s    
end
test_enumerate_children() click to toggle source
# File lib/vendor/xml_node/test/test_parsing.rb, line 27
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
test_find_all() click to toggle source
# File lib/vendor/xml_node/test/test_parsing.rb, line 38
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
test_find_first() click to toggle source
# File lib/vendor/xml_node/test/test_parsing.rb, line 33
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
test_generate_nice_xml() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 66
def test_generate_nice_xml
  assert_equal "<?xml version='1.0'?>\n<feed>\n  <element>test</element>\n  <element/>\n</feed>", XmlNode.new('feed') { |n| n << XmlNode.new('element', 'test'); n << XmlNode.new('element') }.to_xml
end
test_init_sanity() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 9
def test_init_sanity
  assert_raise(ArgumentError) { XmlNode.new }
  assert_nothing_raised { XmlNode.new('feed')}
  assert_nothing_raised { XmlNode.new('feed', 'content') }
  assert_nothing_raised { XmlNode.new('feed', :attribute => true) }
  assert_nothing_raised { XmlNode.new('feed', 'content', :attribute => true) }
end
test_named_namespace() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 60
def test_named_namespace
  node = XmlNode.new('feed')
  node.namespace :opensearch, 'http://a9.com/-/spec/opensearch/1.1/'
  assert_equal "<feed xmlns:opensearch='http://a9.com/-/spec/opensearch/1.1/'/>", node.to_s
end
test_namespace() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 54
def test_namespace
  node = XmlNode.new('feed')
  node.namespace 'http://www.w3.org/2005/Atom'
  assert_equal "<feed xmlns='http://www.w3.org/2005/Atom'/>", node.to_s
end
test_nesting() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 24
def test_nesting
  assert_equal '<feed><element/></feed>', XmlNode.new('feed') { |n| n << XmlNode.new('element') }.to_s
  assert_equal '<feed><element><id>1</id></element></feed>', XmlNode.new('feed') { |n| n << XmlNode.new('element') { |n| n << XmlNode.new('id', '1')} }.to_s
end
test_nil() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 79
def test_nil
  assert_equal '<nil/>', XmlNode.new('nil', nil).to_s
end
test_parse_attributes() click to toggle source
# File lib/vendor/xml_node/test/test_parsing.rb, line 15
def test_parse_attributes
  node = XmlNode.parse('<feed attr="1"/>')
  assert_equal '1', node['attr']
  assert_equal nil, node['attr2']
end
test_parse_children() click to toggle source
# File lib/vendor/xml_node/test/test_parsing.rb, line 21
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
test_parse_sanity() click to toggle source
# File lib/vendor/xml_node/test/test_parsing.rb, line 9
def test_parse_sanity    
  assert_raise(ArgumentError) { XmlNode.parse }
  assert_nothing_raised { XmlNode.parse('<feed/>') }
end
test_text() click to toggle source
# File lib/vendor/xml_node/test/test_generating.rb, line 40
def test_text
  node = XmlNode.new('feed')
  node.text = 'Hello world'
  
  assert_equal '<feed>Hello world</feed>', node.to_s
  assert_equal 'Hello world', node.text
end