From 8f671120f1d99b47f28d67183855d634d006389a Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 20 Apr 2013 23:03:52 +0000 Subject: * test/csv/test_features.rb, test/logger/test_logger.rb test/mkmf/test_have_macro.rb, test/net/http/test_http.rb, test/openssl/test_config.rb, test/psych/test_encoding.rb, test/psych/test_exception.rb, test/psych/test_psych.rb, test/psych/test_tainted.rb, test/readline/test_readline.rb, test/rexml/test_contrib.rb, test/ruby/test_autoload.rb, test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb, test/ruby/test_file.rb, test/ruby/test_io.rb, test/ruby/test_marshal.rb, test/ruby/test_process.rb, test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb, test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb, test/zlib/test_zlib.rb: Use Tempfile.create. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/net/http/test_http.rb | 88 ++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 45 deletions(-) (limited to 'test/net/http/test_http.rb') diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 0b3eeeb6bf..b83844377f 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -599,15 +599,15 @@ module TestNetHTTP_version_1_2_methods def test_set_form require 'tempfile' - file = Tempfile.new('ruby-test') - file << "\u{30c7}\u{30fc}\u{30bf}" - data = [ - ['name', 'Gonbei Nanashi'], - ['name', "\u{540d}\u{7121}\u{3057}\u{306e}\u{6a29}\u{5175}\u{885b}"], - ['s"i\o', StringIO.new("\u{3042 3044 4e9c 925b}")], - ["file", file, filename: "ruby-test"] - ] - expected = <<"__EOM__".gsub(/\n/, "\r\n") + Tempfile.create('ruby-test') {|file| + file << "\u{30c7}\u{30fc}\u{30bf}" + data = [ + ['name', 'Gonbei Nanashi'], + ['name', "\u{540d}\u{7121}\u{3057}\u{306e}\u{6a29}\u{5175}\u{885b}"], + ['s"i\o', StringIO.new("\u{3042 3044 4e9c 925b}")], + ["file", file, filename: "ruby-test"] + ] + expected = <<"__EOM__".gsub(/\n/, "\r\n") -- Content-Disposition: form-data; name="name" @@ -627,13 +627,12 @@ Content-Type: application/octet-stream \xE3\x83\x87\xE3\x83\xBC\xE3\x82\xBF ---- __EOM__ - start {|http| - _test_set_form_urlencoded(http, data.reject{|k,v|!v.is_a?(String)}) - _test_set_form_multipart(http, false, data, expected) - _test_set_form_multipart(http, true, data, expected) + start {|http| + _test_set_form_urlencoded(http, data.reject{|k,v|!v.is_a?(String)}) + _test_set_form_multipart(http, false, data, expected) + _test_set_form_multipart(http, true, data, expected) + } } - ensure - file.close! if file end def _test_set_form_urlencoded(http, data) @@ -658,12 +657,12 @@ __EOM__ def test_set_form_with_file require 'tempfile' - file = Tempfile.new('ruby-test') - file.binmode - file << $test_net_http_data - filename = File.basename(file.to_path) - data = [['file', file]] - expected = <<"__EOM__".gsub(/\n/, "\r\n") + Tempfile.create('ruby-test') {|file| + file.binmode + file << $test_net_http_data + filename = File.basename(file.to_path) + data = [['file', file]] + expected = <<"__EOM__".gsub(/\n/, "\r\n") -- Content-Disposition: form-data; name="file"; filename="" Content-Type: application/octet-stream @@ -671,31 +670,30 @@ Content-Type: application/octet-stream ---- __EOM__ - expected.sub!(//, filename) - expected.sub!(//, $test_net_http_data) - start {|http| - data.each{|k,v|v.rewind rescue nil} - req = Net::HTTP::Post.new('/') - req.set_form(data, 'multipart/form-data') - res = http.request req - body = res.body - header, _ = body.split(/\r\n\r\n/, 2) - assert_match(/\A--(?\S+)/, body) - /\A--(?\S+)/ =~ body - expected = expected.gsub(//, boundary) - assert_match(/^--(?\S+)\r\n/, header) - assert_match( - /^Content-Disposition: form-data; name="file"; filename="#{filename}"\r\n/, - header) - assert_equal(expected, body) - - data.each{|k,v|v.rewind rescue nil} - req['Transfer-Encoding'] = 'chunked' - res = http.request req - #assert_equal(expected, res.body) + expected.sub!(//, filename) + expected.sub!(//, $test_net_http_data) + start {|http| + data.each{|k,v|v.rewind rescue nil} + req = Net::HTTP::Post.new('/') + req.set_form(data, 'multipart/form-data') + res = http.request req + body = res.body + header, _ = body.split(/\r\n\r\n/, 2) + assert_match(/\A--(?\S+)/, body) + /\A--(?\S+)/ =~ body + expected = expected.gsub(//, boundary) + assert_match(/^--(?\S+)\r\n/, header) + assert_match( + /^Content-Disposition: form-data; name="file"; filename="#{filename}"\r\n/, + header) + assert_equal(expected, body) + + data.each{|k,v|v.rewind rescue nil} + req['Transfer-Encoding'] = 'chunked' + res = http.request req + #assert_equal(expected, res.body) + } } - ensure - file.close! if file end end -- cgit v1.2.3