From 5621c872dc766ba73cde3065e80751030cf6ba7b Mon Sep 17 00:00:00 2001 From: Jens Bissinger Date: Thu, 28 Nov 2013 22:16:55 +0100 Subject: [PATCH] Add HTTParty::Error base class. Refs #209. --- lib/httparty/exceptions.rb | 9 ++++++--- spec/httparty/exception_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 spec/httparty/exception_spec.rb diff --git a/lib/httparty/exceptions.rb b/lib/httparty/exceptions.rb index 512aec7d..7451c89d 100644 --- a/lib/httparty/exceptions.rb +++ b/lib/httparty/exceptions.rb @@ -1,13 +1,16 @@ module HTTParty + # @abstact Exceptions raised by HTTParty inherit from Error + class Error < StandardError; end + # Exception raised when you attempt to set a non-existant format - class UnsupportedFormat < StandardError; end + class UnsupportedFormat < Error; end # Exception raised when using a URI scheme other than HTTP or HTTPS - class UnsupportedURIScheme < StandardError; end + class UnsupportedURIScheme < Error; end # @abstract Exceptions which inherit from ResponseError contain the Net::HTTP # response object accessible via the {#response} method. - class ResponseError < StandardError + class ResponseError < Error # Returns the response of the last request # @return [Net::HTTPResponse] A subclass of Net::HTTPResponse, e.g. # Net::HTTPOK diff --git a/spec/httparty/exception_spec.rb b/spec/httparty/exception_spec.rb new file mode 100644 index 00000000..b3d8779e --- /dev/null +++ b/spec/httparty/exception_spec.rb @@ -0,0 +1,23 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) + +describe HTTParty::Error do + subject { described_class } + + its(:ancestors) { should include(StandardError) } + + describe HTTParty::UnsupportedFormat do + its(:ancestors) { should include(HTTParty::Error) } + end + + describe HTTParty::UnsupportedURIScheme do + its(:ancestors) { should include(HTTParty::Error) } + end + + describe HTTParty::ResponseError do + its(:ancestors) { should include(HTTParty::Error) } + end + + describe HTTParty::RedirectionTooDeep do + its(:ancestors) { should include(HTTParty::ResponseError) } + end +end