Skip to content

Commit

Permalink
Add tests to allow symbol-based header hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisGuyCodes committed Feb 7, 2024
1 parent 21b7cf0 commit 68c360a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/stdlib/Net_HTTP_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,33 @@ def test_get
Net::HTTP, :get_print, 'www.ruby-lang.org', '/en'
assert_send_type "(URI::Generic, Hash[String, String]) -> nil",
Net::HTTP, :get_print, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} if RUBY_VERSION >= '3.0'
assert_send_type "(URI::Generic, Hash[Symbol, String]) -> nil",
Net::HTTP, :get_print, URI("https://www.ruby-lang.org"), {Accept: "text/html"} if RUBY_VERSION >= '3.0'
assert_send_type "(URI::Generic) -> String",
Net::HTTP, :get, URI("https://www.ruby-lang.org")
assert_send_type "(String, String) -> String",
Net::HTTP, :get, 'www.ruby-lang.org', '/en'
assert_send_type "(URI::Generic, Hash[String, String]) -> String",
Net::HTTP, :get, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} if RUBY_VERSION >= '3.0'
assert_send_type "(URI::Generic, Hash[Symbol, String]) -> String",
Net::HTTP, :get, URI("https://www.ruby-lang.org"), {Accept: "text/html"} if RUBY_VERSION >= '3.0'
assert_send_type "(URI::Generic) -> Net::HTTPResponse",
Net::HTTP, :get_response, URI("https://www.ruby-lang.org")
assert_send_type "(String, String) -> Net::HTTPResponse",
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'
assert_send_type "(URI::Generic, Hash[Symbol, 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
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, String, Hash[Symbol, 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
Expand Down Expand Up @@ -169,6 +177,8 @@ def test_http_verbs
Net::HTTP.start('www.ruby-lang.org', 443, use_ssl: true), :get, '/en'
assert_send_type "(String, Hash[String, String]) -> Net::HTTPResponse",
Net::HTTP.start('www.ruby-lang.org', 443, use_ssl: true), :get, '/en', { "Accept" => "text/html" }
assert_send_type "(String, Hash[Symbol, String]) -> Net::HTTPResponse",
Net::HTTP.start('www.ruby-lang.org', 443, use_ssl: true), :get, '/en', { Accept: "text/html" }
assert_send_type "(String) { (String) -> untyped } -> Net::HTTPResponse",
Net::HTTP.start('www.ruby-lang.org', 443, use_ssl: true), :get, '/en' do |string| string end
assert_send_type "(String, Hash[String, String]) { (String) -> untyped } -> Net::HTTPResponse",
Expand Down

0 comments on commit 68c360a

Please sign in to comment.