1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Fixed tests

This commit is contained in:
Julien Kirch 2010-01-20 19:57:38 +01:00
parent f71ddf4bea
commit 26aa3ce8d0
2 changed files with 10 additions and 12 deletions

View file

@ -2,6 +2,10 @@ module RestClient
# This is the base RestClient exception class. Rescue it if you want to
# catch any exception that your request might raise
# You can get the status code by e.http_code, or see anything about the
# response via e.response.
# For example, the entire result body (which is
# probably an HTML error page) is e.response.
class Exception < RuntimeError
attr_accessor :message, :response
@ -10,7 +14,8 @@ module RestClient
end
def http_code
@response.code if @response
# return integer for compatibility
@response.code.to_i if @response
end
def http_body
@ -81,12 +86,7 @@ module RestClient
end
# The request failed, meaning the remote HTTP server returned a code other
# than success, unauthorized, or redirect.
#
# You can get the status code by e.http_code, or see anything about the
# response via e.response. For example, the entire result body (which is
# probably an HTML error page) is e.response.body.
# The request failed with an error code not managed by the code
class RequestFailed < Exception
def message

View file

@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/base'
describe RestClient::Exception do
it "sets the exception message to ErrorMessage" do
RestClient::ResourceNotFound.new.message.should == 'Resource not found'
RestClient::ResourceNotFound.new.message.should == 'Resource Not Found'
end
it "contains exceptions in RestClient" do
@ -29,10 +29,8 @@ describe RestClient::RequestFailed do
end
it "http_body convenience method for fetching the body (decoding when necessary)" do
@response.stub!(:[]).with('content-encoding').and_return('gzip')
@response.stub!(:body).and_return('compressed body')
RestClient::Request.should_receive(:decode).with('gzip', 'compressed body').and_return('plain body')
RestClient::RequestFailed.new(@response).http_body.should == 'plain body'
RestClient::RequestFailed.new(@response).http_code.should == 502
RestClient::RequestFailed.new(@response).message.should == 'HTTP status code 502'
end
it "shows the status code in the message" do