From f8b76cd8fd190e295e1008294624365c33c3086a Mon Sep 17 00:00:00 2001 From: kou Date: Sat, 22 Feb 2014 14:03:25 +0000 Subject: * test/rexml/xpath/test_attribute.rb: Simplify. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rexml/xpath/test_attribute.rb | 92 +++++++------------------------------- 1 file changed, 17 insertions(+), 75 deletions(-) (limited to 'test/rexml/xpath') diff --git a/test/rexml/xpath/test_attribute.rb b/test/rexml/xpath/test_attribute.rb index 9af83a3081..81a39bb9d2 100644 --- a/test/rexml/xpath/test_attribute.rb +++ b/test/rexml/xpath/test_attribute.rb @@ -2,84 +2,26 @@ require 'test/unit' require 'rexml/document' class TestXPathAttribute < Test::Unit::TestCase - - # xmlstr1 and xmlstr2 only differ in the second line - namespaces in the root element - @@xmlstr1 = ' - - http://www.google.com/calendar/feeds/me%40gmail.com - - http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com - 2007-05-16T13:42:27.942Z - 2007-05-15T03:29:28.000Z - My Calendar - - - - - Me - me@gmail.com - - -' - - - @@xmlstr2 = ' - - http://www.google.com/calendar/feeds/me%40gmail.com - - http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com - 2007-05-16T13:42:27.942Z - 2007-05-15T03:29:28.000Z - My Calendar - - - - - Me - me@gmail.com - - -' - - # Fails - def test_xpath_query - do_test @@xmlstr1 + def setup + @xml = <<-XML + + + child1 + child2 + child3 + + XML + @document = REXML::Document.new(@xml) end - # Passes - def test_xpath_query_no_namespace - do_test @@xmlstr2 + def test_elements + root = @document.elements["root"] + second_child = root.elements["child[@name='two']"] + assert_equal("child2", second_child.text) end - def do_test(xmlString) - hrefs = [ - "http://www.google.com/calendar/feeds/me%40gmail.com/private/full", - "http://www.google.com/calendar/feeds/me%40gmail.com/acl/full", - "http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com" - ] - ctr=0 - REXML::Document.new(xmlString).elements.each("feed/entry") do |element| - @alternate_link = element.elements["link[@rel='alternate']"] - assert_not_nil( @alternate_link ) - assert_equal( hrefs[ctr], @alternate_link.attributes['href']) - ctr += 1 - end - end - - - def test_another_way - doc = REXML::Document.new(@@xmlstr1) - hrefs = [ - "http://www.google.com/calendar/feeds/me%40gmail.com/private/full", - "http://www.google.com/calendar/feeds/me%40gmail.com/acl/full", - "http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com" - ] - ctr=0 - REXML::XPath.each(doc, "//link[@rel='alternate']") do |element| - @alternate_link = element - assert_not_nil @alternate_link - assert_equal( hrefs[ctr], @alternate_link.attributes['href']) - ctr += 1 - end + def test_xpath_each + children = REXML::XPath.each(@document, "/root/child[@name='two']") + assert_equal(["child2"], children.collect(&:text)) end end -- cgit v1.2.3