1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Add Ruby 2.6 compatibility and tests (#636)

On ruby/ruby@660740a75d , some status
codes have been updated.
Add aliases so old names can still be used with ruby >= 2.6
This commit is contained in:
Théophile Helleboid - chtitux 2019-01-21 14:33:26 +01:00 committed by Nikita Misharin
parent e59472b5ba
commit d84a05b69e
3 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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)