summaryrefslogtreecommitdiff
path: root/test/open-uri/test_open-uri.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/open-uri/test_open-uri.rb')
-rw-r--r--test/open-uri/test_open-uri.rb43
1 files changed, 42 insertions, 1 deletions
diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb
index 72ebcdb0da..30e3b5c9c1 100644
--- a/test/open-uri/test_open-uri.rb
+++ b/test/open-uri/test_open-uri.rb
@@ -172,6 +172,19 @@ class TestOpenURI < Test::Unit::TestCase
assert_raise(ArgumentError) { URI.open("http://127.0.0.1/", :invalid_option=>true) {} }
end
+ def test_pass_keywords
+ begin
+ f = URI.open(File::NULL, mode: 0666)
+ assert_kind_of File, f
+ ensure
+ f&.close
+ end
+
+ o = Object.new
+ def o.open(foo: ) foo end
+ assert_equal 1, URI.open(o, foo: 1)
+ end
+
def test_mode
with_http {|srv, dr, url|
srv.mount_proc("/mode", lambda { |req, res| res.body = "mode" } )
@@ -545,6 +558,25 @@ class TestOpenURI < Test::Unit::TestCase
}
end
+ def test_max_redirects_success
+ with_http {|srv, dr, url|
+ srv.mount_proc("/r1/") {|req, res| res.status = 301; res["location"] = "#{url}/r2"; res.body = "r1" }
+ srv.mount_proc("/r2/") {|req, res| res.status = 301; res["location"] = "#{url}/r3"; res.body = "r2" }
+ srv.mount_proc("/r3/") {|req, res| res.body = "r3" }
+ URI.open("#{url}/r1/", max_redirects: 2) { |f| assert_equal("r3", f.read) }
+ }
+ end
+
+ def test_max_redirects_too_many
+ with_http {|srv, dr, url|
+ srv.mount_proc("/r1/") {|req, res| res.status = 301; res["location"] = "#{url}/r2"; res.body = "r1" }
+ srv.mount_proc("/r2/") {|req, res| res.status = 301; res["location"] = "#{url}/r3"; res.body = "r2" }
+ srv.mount_proc("/r3/") {|req, res| res.body = "r3" }
+ exc = assert_raise(OpenURI::TooManyRedirects) { URI.open("#{url}/r1/", max_redirects: 1) {} }
+ assert_equal("Too many redirects", exc.message)
+ }
+ end
+
def test_userinfo
assert_raise(ArgumentError) { URI.open("http://user:pass@127.0.0.1/") {} }
end
@@ -902,5 +934,14 @@ class TestOpenURI < Test::Unit::TestCase
}
end
-end
+ def test_meta_init_doesnt_bump_global_constant_state
+ omit "RubyVM.stat not defined" unless defined? RubyVM.stat
+ omit unless RubyVM.stat.has_key?(:global_constant_state)
+
+ OpenURI::Meta.init(Object.new) # prewarm
+ before = RubyVM.stat(:global_constant_state)
+ OpenURI::Meta.init(Object.new)
+ assert_equal 0, RubyVM.stat(:global_constant_state) - before
+ end
+end