2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../../../spec_helper'
|
2017-05-07 08:04:49 -04:00
|
|
|
require 'net/http'
|
|
|
|
|
|
|
|
describe "Net::HTTPResponse#value" do
|
|
|
|
it "raises an HTTP error for non 2xx HTTP Responses" do
|
|
|
|
res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { res.value }.should raise_error(Net::HTTPError)
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
res = Net::HTTPInformation.new("1.0", "1xx", "test response")
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { res.value }.should raise_error(Net::HTTPError)
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { res.value }.should_not raise_error(Net::HTTPError)
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { res.value }.should raise_error(Net::HTTPRetriableError)
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
res = Net::HTTPClientError.new("1.0", "4xx", "test response")
|
2018-06-14 02:41:09 -04:00
|
|
|
ruby_version_is ""..."2.6" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { res.value }.should raise_error(Net::HTTPServerException)
|
2018-06-14 02:41:09 -04:00
|
|
|
end
|
|
|
|
ruby_version_is "2.6" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { res.value }.should raise_error(Net::HTTPClientException)
|
2018-06-14 02:41:09 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
res = Net::HTTPServerError.new("1.0", "5xx", "test response")
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { res.value }.should raise_error(Net::HTTPFatalError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|