require 'test_helper' class TestNode < Test::Unit::TestCase def test_elements assert doc.elements.size == 1 assert doc.at('root').elements.size == 2 end def test_text_element assert doc(<<-XML).at('root').text_element? hello XML end def test_match_of_elements_without_comparing_values subject = doc(<<-XML) 1 3 XML pattern = doc(<<-XML) 2 XML assert subject.match?(pattern) end def test_no_match_of_elements_without_comparing_values subject = doc(<<-XML) 1 XML pattern = doc(<<-XML) 5 XML assert !subject.match?(pattern) end def test_match_with_values subject = doc(<<-XML) 1 3 XML pattern = doc(<<-XML) 3 1 XML assert subject.match?(pattern, true) end def test_no_match_with_values subject = doc(<<-XML) 1 XML not_matched_pattern = doc(<<-XML) 2 XML assert !subject.match?(not_matched_pattern, true) end def test_element_contains_another_element element = create_element('') assert !doc.send(:contains?,element) assert doc.at('root').send(:contains?,element) end def test_element_contains_elements assert doc.root.send(:contains_elements_of?, doc.root) assert !doc.root.send(:contains_elements_of?, doc('')) end private def create_element(xml) Nokogiri::XML::Document.parse(xml).root end def doc(xml = nil) xml ||= <<-XML 1 2 XML Nokogiri::XML::Document.parse(xml) end end