From bf287424fd00c0304c836525bb52d89fc1f4a84a Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 21 Dec 2017 14:15:04 +0000 Subject: open-uri defines URI.open defined as an alias. open-uri's Kernel.open will be deprecated in future. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- NEWS | 4 ++++ lib/open-uri.rb | 7 +++++++ test/open-uri/test_open-uri.rb | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/NEWS b/NEWS index 9d9898fcf4..05ebb37717 100644 --- a/NEWS +++ b/NEWS @@ -295,6 +295,10 @@ with all sufficient information, see the ChangeLog file or Redmine * Net::HTTP#{proxy_user,proxy_pass} reflect http_proxy environment variable if the system's environment variable is multiuser safe. [Bug #12921] +* open-uri + * URI.open method defined as an alias to open-uri's Kernel.open. + open-uri's Kernel.open will be deprecated in future. + * OpenSSL * Updated Ruby/OpenSSL from version 2.0 to 2.1. Changes are noted in diff --git a/lib/open-uri.rb b/lib/open-uri.rb index a68413e8f8..c0ef89c2ec 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -40,6 +40,13 @@ module Kernel module_function :open end +module URI #:nodoc: + # alias for Kernel.open defined in open-uri. + def self.open(name, *rest, &block) + Kernel.open(name, *rest, &block) + end +end + # OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP. # # == Example diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb index 3feed423a0..0301483902 100644 --- a/test/open-uri/test_open-uri.rb +++ b/test/open-uri/test_open-uri.rb @@ -68,6 +68,16 @@ class TestOpenURI < Test::Unit::TestCase @proxies.each_with_index {|k, i| ENV[k] = @old_proxies[i] } end + def test_200_uri_open + with_http {|srv, dr, url| + srv.mount_proc("/urifoo200", lambda { |req, res| res.body = "urifoo200" } ) + URI.open("#{url}/urifoo200") {|f| + assert_equal("200", f.status[0]) + assert_equal("urifoo200", f.read) + } + } + end + def test_200 with_http {|srv, dr, url| srv.mount_proc("/foo200", lambda { |req, res| res.body = "foo200" } ) -- cgit v1.2.3