From 3356c312cddcc95af59e648c4ad946ec969d9813 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 27 May 2014 13:45:04 +0000 Subject: * test/rexml: Avoid fd leaks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rexml/xpath/test_base.rb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'test/rexml/xpath/test_base.rb') diff --git a/test/rexml/xpath/test_base.rb b/test/rexml/xpath/test_base.rb index 8ef5e4aff0..a57ba632c4 100644 --- a/test/rexml/xpath/test_base.rb +++ b/test/rexml/xpath/test_base.rb @@ -130,7 +130,9 @@ module REXMLTests assert_equal("b", XPath::first(c, "..").name) assert_equal("a", XPath::first(@@doc, "a/b/..").name) - doc = REXML::Document.new(File.new(fixture_path("project.xml"))) + doc = File.open(fixture_path("project.xml")) do |f| + REXML::Document.new(f) + end c = each_test(doc.root, "./Description" ) { |child| assert_equal("Description",child.name) } @@ -213,11 +215,11 @@ module REXMLTests xmlsource = fixture_path("testsrc.xml") xpathtests = fixture_path("xp.tst") - doc = REXML::Document.new(File.new(xmlsource)) + doc = File.open(xmlsource) {|f| REXML::Document.new(f) } #results = "" results = REXML::Document.new results.add_element "test-results" - for line in File.new(xpathtests) + File.foreach(xpathtests) do |line| line.strip! begin doc.root @@ -315,7 +317,7 @@ module REXMLTests end def test_lang - doc = Document.new(File.new(fixture_path("lang0.xml"))) + doc = File.open(fixture_path("lang0.xml")) {|f| Document.new(f) } #puts IO.read( "test/lang.xml" ) #puts XPath.match( doc, "//language/*" ).size @@ -936,10 +938,14 @@ EOF def test_ticket_43 #url = http://news.search.yahoo.com/news/rss?p=market&ei=UTF-8&fl=0&x=wrt - sum = Document.new(File.new(fixture_path("yahoo.xml"))).elements.to_a("//item").size + sum = File.open(fixture_path("yahoo.xml")) do |f| + Document.new(f).elements.to_a("//item").size + end assert_equal( 10, sum ) - text = Document.new(File.new(fixture_path("yahoo.xml"))).elements.to_a(%Q{//title[contains(text(), "'")]}).collect{|e| e.text}.join + text = File.open(fixture_path("yahoo.xml")) do |f| + Document.new(f).elements.to_a(%Q{//title[contains(text(), "'")]}).collect{|e| e.text}.join + end assert_equal( "Broward labor market's a solid performer (Miami Herald)", text ) end @@ -997,14 +1003,16 @@ EOF end def test_ticket_61_text - file = File.open(fixture_path("ticket_61.xml")) - doc = REXML::Document.new file + doc = File.open(fixture_path("ticket_61.xml")) do |file| + REXML::Document.new file + end ticket_61_fixture( doc, "//div[text()='Add' and @class='ButtonText']" ) end def test_ticket_61_contains - file = File.open(fixture_path("ticket_61.xml")) - doc = REXML::Document.new file + doc = File.open(fixture_path("ticket_61.xml")) do |file| + REXML::Document.new file + end ticket_61_fixture( doc, "//div[contains(.,'Add') and @class='ButtonText']" ) end -- cgit v1.2.3