From d84a05b69e96c470768fd9edd1f55db3db47f6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Helleboid=20-=20chtitux?= Date: Mon, 21 Jan 2019 14:33:26 +0100 Subject: [PATCH] Add Ruby 2.6 compatibility and tests (#636) On ruby/ruby@660740a75dd9526ad9a2732ea87c8ab5a385ef1f , some status codes have been updated. Add aliases so old names can still be used with ruby >= 2.6 --- .travis.yml | 1 + lib/httparty/response.rb | 9 +++++++++ spec/httparty/response_spec.rb | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/.travis.yml b/.travis.yml index 20516e6..2bdda3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,6 @@ rvm: - 2.3.8 - 2.4.5 - 2.5.3 + - 2.6.0 bundler_args: --without development before_install: gem install bundler diff --git a/lib/httparty/response.rb b/lib/httparty/response.rb index 4ae7baf..99051fc 100644 --- a/lib/httparty/response.rb +++ b/lib/httparty/response.rb @@ -65,6 +65,15 @@ module HTTParty 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" + alias_method :gateway_time_out?, :gateway_timeout? + alias_method :request_entity_too_large?, :payload_too_large? + alias_method :request_time_out?, :request_timeout? + alias_method :request_uri_too_long?, :uri_too_long? + alias_method :requested_range_not_satisfiable?, :range_not_satisfiable? + end + def nil? response.nil? || response.body.nil? || response.body.empty? end diff --git a/spec/httparty/response_spec.rb b/spec/httparty/response_spec.rb index 7ee6aed..dde0259 100644 --- a/spec/httparty/response_spec.rb +++ b/spec/httparty/response_spec.rb @@ -282,6 +282,15 @@ RSpec.describe HTTParty::Response do 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" + SPECIFIC_CODES[:gateway_timeout?] = Net::HTTPGatewayTimeout + SPECIFIC_CODES[:payload_too_large?] = Net::HTTPPayloadTooLarge + SPECIFIC_CODES[:request_timeout?] = Net::HTTPRequestTimeout + SPECIFIC_CODES[:uri_too_long?] = Net::HTTPURITooLong + SPECIFIC_CODES[:range_not_satisfiable?] = Net::HTTPRangeNotSatisfiable + end + SPECIFIC_CODES.each do |method, klass| it "responds to #{method}" do net_response = response_mock(klass)