From 322785d6fbdb8f5e0017c4aaf97e1f9d2ef613fe Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Wed, 20 Mar 2024 09:08:52 -0400 Subject: [PATCH] Drop old ruby support Keeping 2.7 even though its EOL because kind john is kind. --- .github/workflows/ci.yml | 6 +- httparty.gemspec | 2 +- lib/httparty/connection_adapter.rb | 29 +---- lib/httparty/response.rb | 4 +- spec/httparty/connection_adapter_spec.rb | 130 ++++++++++------------- spec/httparty/response_spec.rb | 5 +- 6 files changed, 69 insertions(+), 107 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fce1904..817b08e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,12 +6,8 @@ jobs: strategy: matrix: ruby: - - 2.3 - - 2.4 - - 2.5 - - 2.6 - 2.7 - - '3.0' # Quoted, to avoid YAML float 3.0 interplated to "3" + - "3.0" # Quoted, to avoid YAML float 3.0 interplated to "3" - 3.1 - 3.2 - 3.3 diff --git a/httparty.gemspec b/httparty.gemspec index 9ce269d7..b0d5fded 100644 --- a/httparty.gemspec +++ b/httparty.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.summary = 'Makes http fun! Also, makes consuming restful web services dead easy.' s.description = 'Makes http fun! Also, makes consuming restful web services dead easy.' - s.required_ruby_version = '>= 2.3.0' + s.required_ruby_version = '>= 2.7.0' s.add_dependency 'csv' s.add_dependency 'multi_xml', ">= 0.5.2" diff --git a/lib/httparty/connection_adapter.rb b/lib/httparty/connection_adapter.rb index 9dd130d2..262016fb 100644 --- a/lib/httparty/connection_adapter.rb +++ b/lib/httparty/connection_adapter.rb @@ -119,10 +119,7 @@ def connection if add_timeout?(options[:timeout]) http.open_timeout = options[:timeout] http.read_timeout = options[:timeout] - - from_ruby_version('2.6.0', option: :write_timeout, warn: false) do - http.write_timeout = options[:timeout] - end + http.write_timeout = options[:timeout] end if add_timeout?(options[:read_timeout]) @@ -134,15 +131,11 @@ def connection end if add_timeout?(options[:write_timeout]) - from_ruby_version('2.6.0', option: :write_timeout) do - http.write_timeout = options[:write_timeout] - end + http.write_timeout = options[:write_timeout] end if add_max_retries?(options[:max_retries]) - from_ruby_version('2.5.0', option: :max_retries) do - http.max_retries = options[:max_retries] - end + http.max_retries = options[:max_retries] end if options[:debug_output] @@ -157,15 +150,11 @@ def connection # # @see https://bugs.ruby-lang.org/issues/6617 if options[:local_host] - from_ruby_version('2.0.0', option: :local_host) do - http.local_host = options[:local_host] - end + http.local_host = options[:local_host] end if options[:local_port] - from_ruby_version('2.0.0', option: :local_port) do - http.local_port = options[:local_port] - end + http.local_port = options[:local_port] end http @@ -173,14 +162,6 @@ def connection private - def from_ruby_version(ruby_version, option: nil, warn: true) - if RUBY_VERSION >= ruby_version - yield - elsif warn - Kernel.warn("Warning: option #{ option } requires Ruby version #{ ruby_version } or later") - end - end - def add_timeout?(timeout) timeout && (timeout.is_a?(Integer) || timeout.is_a?(Float)) end diff --git a/lib/httparty/response.rb b/lib/httparty/response.rb index 4a93181d..2a6fa42b 100644 --- a/lib/httparty/response.rb +++ b/lib/httparty/response.rb @@ -67,12 +67,12 @@ def inspect end # Support old multiple_choice? method from pre 2.0.0 era. - if ::RUBY_VERSION >= '2.0.0' && ::RUBY_PLATFORM != 'java' + if ::RUBY_PLATFORM != 'java' alias_method :multiple_choice?, :multiple_choices? end # Support old status codes method from pre 2.6.0 era. - if ::RUBY_VERSION >= '2.6.0' && ::RUBY_PLATFORM != 'java' + if ::RUBY_PLATFORM != 'java' alias_method :gateway_time_out?, :gateway_timeout? alias_method :request_entity_too_large?, :payload_too_large? alias_method :request_time_out?, :request_timeout? diff --git a/spec/httparty/connection_adapter_spec.rb b/spec/httparty/connection_adapter_spec.rb index 098fa52c..de386f87 100644 --- a/spec/httparty/connection_adapter_spec.rb +++ b/spec/httparty/connection_adapter_spec.rb @@ -102,7 +102,7 @@ it "sets ssl version" do expect(subject.ssl_version).to eq(:TLSv1) end - end if RUBY_VERSION > '1.9' + end end context "when dealing with IPv6" do @@ -119,7 +119,7 @@ it "should set the ciphers on the connection" do expect(subject.ciphers).to eq('RC4-SHA') end - end if RUBY_VERSION > '1.9' + end context "when timeout is not set" do it "doesn't set the timeout" do @@ -152,11 +152,9 @@ it { is_expected.to eq(5) } end - if RUBY_VERSION >= '2.6.0' - describe '#write_timeout' do - subject { super().write_timeout } - it { is_expected.to eq(5) } - end + describe '#write_timeout' do + subject { super().write_timeout } + it { is_expected.to eq(5) } end end @@ -223,11 +221,9 @@ it { is_expected.to eq(5) } end - if RUBY_VERSION >= '2.6.0' - describe '#write_timeout' do - subject { super().write_timeout } - it { is_expected.to eq(5) } - end + describe '#write_timeout' do + subject { super().write_timeout } + it { is_expected.to eq(5) } end describe '#read_timeout' do @@ -247,9 +243,7 @@ ) expect(http).to receive(:open_timeout=) expect(http).to receive(:read_timeout=).twice - if RUBY_VERSION >= '2.6.0' - expect(http).to receive(:write_timeout=) - end + expect(http).to receive(:write_timeout=) allow(Net::HTTP).to receive_messages(new: http) adapter.connection end @@ -298,11 +292,9 @@ it { is_expected.to eq(7) } end - if RUBY_VERSION >= '2.6.0' - describe '#write_timeout' do - subject { super().write_timeout } - it { is_expected.to eq(5) } - end + describe '#write_timeout' do + subject { super().write_timeout } + it { is_expected.to eq(5) } end describe '#read_timeout' do @@ -322,54 +314,50 @@ ) expect(http).to receive(:open_timeout=).twice expect(http).to receive(:read_timeout=) - if RUBY_VERSION >= '2.6.0' - expect(http).to receive(:write_timeout=) - end + expect(http).to receive(:write_timeout=) allow(Net::HTTP).to receive_messages(new: http) adapter.connection end end - if RUBY_VERSION >= '2.6.0' - context "when timeout is not set and write_timeout is set to 8 seconds" do - let(:options) { {write_timeout: 8} } + context "when timeout is not set and write_timeout is set to 8 seconds" do + let(:options) { {write_timeout: 8} } - describe '#write_timeout' do - subject { super().write_timeout } - it { is_expected.to eq(8) } - end + describe '#write_timeout' do + subject { super().write_timeout } + it { is_expected.to eq(8) } + end - it "should not set the open timeout" do - http = double( - "http", - :null_object => true, - :use_ssl= => false, - :use_ssl? => false, - :read_timeout= => 0, - :open_timeout= => 0, - :write_timeout= => 0, + it "should not set the open timeout" do + http = double( + "http", + :null_object => true, + :use_ssl= => false, + :use_ssl? => false, + :read_timeout= => 0, + :open_timeout= => 0, + :write_timeout= => 0, - ) - expect(http).not_to receive(:open_timeout=) - allow(Net::HTTP).to receive_messages(new: http) - adapter.connection - end + ) + expect(http).not_to receive(:open_timeout=) + allow(Net::HTTP).to receive_messages(new: http) + adapter.connection + end - it "should not set the read timeout" do - http = double( - "http", - :null_object => true, - :use_ssl= => false, - :use_ssl? => false, - :read_timeout= => 0, - :open_timeout= => 0, - :write_timeout= => 0, + it "should not set the read timeout" do + http = double( + "http", + :null_object => true, + :use_ssl= => false, + :use_ssl? => false, + :read_timeout= => 0, + :open_timeout= => 0, + :write_timeout= => 0, - ) - expect(http).not_to receive(:read_timeout=) - allow(Net::HTTP).to receive_messages(new: http) - adapter.connection - end + ) + expect(http).not_to receive(:read_timeout=) + allow(Net::HTTP).to receive_messages(new: http) + adapter.connection end context "when timeout is set and write_timeout is set to 8 seconds" do @@ -415,21 +403,19 @@ end context "when setting max_retries" do - if RUBY_VERSION >= '2.5.0' - context "to 5 times" do - let(:options) { {max_retries: 5} } - describe '#max_retries' do - subject { super().max_retries } - it { is_expected.to eq(5) } - end + context "to 5 times" do + let(:options) { {max_retries: 5} } + describe '#max_retries' do + subject { super().max_retries } + it { is_expected.to eq(5) } end + end - context "to 0 times" do - let(:options) { {max_retries: 0} } - describe '#max_retries' do - subject { super().max_retries } - it { is_expected.to eq(0) } - end + context "to 0 times" do + let(:options) { {max_retries: 0} } + describe '#max_retries' do + subject { super().max_retries } + it { is_expected.to eq(0) } end end @@ -545,7 +531,7 @@ subject { super().local_port } it { is_expected.to eq(12345) } end - end if RUBY_VERSION >= '2.0' + end context "when providing PEM certificates" do let(:pem) { :pem_contents } diff --git a/spec/httparty/response_spec.rb b/spec/httparty/response_spec.rb index fc653981..7884aa09 100644 --- a/spec/httparty/response_spec.rb +++ b/spec/httparty/response_spec.rb @@ -305,13 +305,12 @@ def response_mock(klass) version_not_supported?: Net::HTTPVersionNotSupported } - # Ruby 2.0, new name for this response. - if RUBY_VERSION >= "2.0.0" && ::RUBY_PLATFORM != "java" + if ::RUBY_PLATFORM != "java" SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices end # Ruby 2.6, those status codes have been updated. - if RUBY_VERSION >= "2.6.0" && ::RUBY_PLATFORM != "java" + if ::RUBY_PLATFORM != "java" SPECIFIC_CODES[:gateway_timeout?] = Net::HTTPGatewayTimeout SPECIFIC_CODES[:payload_too_large?] = Net::HTTPPayloadTooLarge SPECIFIC_CODES[:request_timeout?] = Net::HTTPRequestTimeout