Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Net_HTTP_test #759

Merged
merged 1 commit into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion test/stdlib/Net_HTTP_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class NetSingletonTest < Test::Unit::TestCase
testing "singleton(::Net::HTTP)"

def test_get
omit if ci?

$stdout = StringIO.new
assert_send_type "(URI::Generic) -> nil",
Net::HTTP, :get_print, URI("https://www.ruby-lang.org")
assert_send_type "(String, String) -> nil",
Expand All @@ -27,16 +30,22 @@ def test_get
Net::HTTP, :get_response, 'www.ruby-lang.org', '/en'
assert_send_type "(URI::Generic, Hash[String, String]) -> Net::HTTPResponse",
Net::HTTP, :get_response, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} if RUBY_VERSION >= '3.0'
ensure
$stdout = STDOUT
end

def test_post
omit if ci?

assert_send_type "(URI, String, Hash[String, String]) -> Net::HTTPResponse",
Net::HTTP, :post, URI('http://www.example.com/api/search'), { "q" => "ruby", "max" => "50" }.to_json, "Content-Type" => "application/json"
assert_send_type "(URI, Hash[String, Symbol]) -> Net::HTTPResponse",
Net::HTTP, :post_form, URI('http://www.example.com/api/search'), { "q" => :ruby, "max" => :max }
end

def test_new
omit if ci?

assert_send_type "(String, Integer, nil, nil, nil, nil, nil) -> Net::HTTP",
Net::HTTP, :new, 'www.ruby-lang.org', 80, nil, nil, nil, nil, nil
end
Expand All @@ -55,92 +64,114 @@ def self.new
end

def test_inspect
omit if ci?

assert_send_type "() -> String",
TestNet.new, :inspect
end

def test_set_debug_output
omit if ci?
assert_send_type "(IO) -> void",
TestNet.new, :set_debug_output, $stderr
end

def test_address
omit if ci?
assert_send_type "() -> String",
TestNet.new, :address
end

def test_port
omit if ci?
assert_send_type "() -> Integer",
TestNet.new, :port
end

def test_ipaddr
omit if ci?
assert_send_type "() -> nil",
TestNet.new, :ipaddr
assert_send_type "(String) -> void",
TestNet.new, :ipaddr=, ('127.0.0.1')
end

def test_open_timeout
omit if ci?
assert_send_type "() -> Integer",
TestNet.new, :open_timeout
end

def test_read_timeout
omit if ci?
assert_send_type "() -> Integer",
TestNet.new, :read_timeout
assert_send_type "(Integer) -> void",
TestNet.new, :read_timeout=, 10
end

def test_write_timeout
omit if ci?
assert_send_type "() -> Integer",
TestNet.new, :write_timeout
assert_send_type "(Integer) -> void",
TestNet.new, :write_timeout=, 10
end

def test_continue_timeout
omit if ci?
assert_send_type "() -> nil",
TestNet.new, :continue_timeout
assert_send_type "(Integer) -> void",
TestNet.new, :continue_timeout=, 10
end

def test_max_retries
omit if ci?

assert_send_type "() -> Integer",
TestNet.new, :max_retries
assert_send_type "(Integer) -> void",
TestNet.new, :max_retries=, 10
end

def test_keep_alive_timeout
omit if ci?

assert_send_type "() -> Integer",
TestNet.new, :keep_alive_timeout
end

def test_started_?
omit if ci?

assert_send_type "() -> bool",
TestNet.new, :started?
assert_send_type "() -> bool",
TestNet.new, :active?
end

def test_use_ssl
omit if ci?

assert_send_type "() -> bool",
TestNet.new, :use_ssl?
assert_send_type "(bool) -> void",
TestNet.new, :use_ssl=, true
end

def test_start
omit if ci?

assert_send_type "() { (Net::HTTP) -> untyped } -> untyped",
TestNet.new, :start do |net_http| net_http.class end
assert_send_type "() -> Net::HTTP",
TestNet.new, :start
end

def test_proxy
omit if ci?

assert_send_type "() -> bool",
TestNet.new, :proxy?
assert_send_type "() -> bool",
Expand All @@ -162,6 +193,8 @@ def test_proxy
end

def test_http_verbs
omit if ci?

assert_send_type "(String) -> Net::HTTPResponse",
Net::HTTP.start('www.ruby-lang.org', 443, use_ssl: true), :get, '/en'
assert_send_type "(String, Hash[String, String]) -> Net::HTTPResponse",
Expand Down Expand Up @@ -293,6 +326,8 @@ def test_http_verbs
end

def test_request
omit if ci?

assert_send_type "(String, String) -> Net::HTTPResponse",
Net::HTTP.start('reqres.in', 443, use_ssl: true), :send_request, 'GET', 'api/users'
assert_send_type "(String, String, String, Hash[String, String]) -> Net::HTTPResponse",
Expand All @@ -311,11 +346,15 @@ class TestHTTPRequest < Test::Unit::TestCase
testing "::Net::HTTPRequest"

def test_inspect
omit if ci?

assert_send_type "() -> String",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :inspect
end

def test_attr_readers
omit if ci?

assert_send_type "() -> String",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :method
assert_send_type "() -> String",
Expand All @@ -327,6 +366,8 @@ def test_attr_readers
end

def test_body
omit if ci?

assert_send_type "() -> bool",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :request_body_permitted?
assert_send_type "() -> bool",
Expand All @@ -344,6 +385,8 @@ def test_body
end

def test_manipulation_of_headers
omit if ci?

assert_send_type "(String) -> nil",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :[], "Content-Type"
assert_send_type "(String, untyped) -> void",
Expand Down Expand Up @@ -417,6 +460,8 @@ def test_manipulation_of_headers
end

def test_iteration_on_headers
omit if ci?

assert_send_type "() { (String, String) -> untyped } -> Hash[String, Array[String]]",
Net::HTTP::Get.new(URI('https://www.ruby-lang.org')), :each_header do |str, array| "#{str} #{array}" end
assert_send_type "() -> Enumerator[[String, String], Hash[String, Array[String]]]",
Expand Down Expand Up @@ -475,6 +520,8 @@ def self.success
end

def test_attr_readers
omit if ci?

assert_send_type "() -> String",
Foo.success, :http_version
assert_send_type "() -> String",
Expand All @@ -490,6 +537,8 @@ def test_attr_readers
end

def test_manipulation_function
omit if ci?

assert_send_type "() -> String",
Foo.success, :inspect
assert_send_type "() -> untyped",
Expand All @@ -509,4 +558,4 @@ def test_manipulation_function
assert_send_type "() -> String",
Foo.success, :entity
end
end
end
4 changes: 4 additions & 0 deletions test/stdlib/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ def method_types(method)
end
end

def ci?
ENV["CI"] == "true"
end

def allows_error(*errors)
yield
rescue *errors => exn
Expand Down