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

45 lines
1.4 KiB
Ruby
Raw Normal View History

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'
end
it "contains exceptions in RestClient" do
RestClient::Unauthorized.new.should be_a_kind_of(RestClient::Exception)
RestClient::ServerBrokeConnection.new.should be_a_kind_of(RestClient::Exception)
end
end
describe RestClient::RequestFailed do
2008-07-20 14:48:52 -04:00
it "stores the http response on the exception" do
begin
raise RestClient::RequestFailed, :response
rescue RestClient::RequestFailed => e
e.response.should == :response
end
end
2008-07-20 14:48:52 -04:00
it "http_code convenience method for fetching the code as an integer" do
RestClient::RequestFailed.new(mock('res', :code => '502')).http_code.should == 502
end
2008-07-20 14:48:52 -04:00
it "shows the status code in the message" do
RestClient::RequestFailed.new(mock('res', :code => '502')).to_s.should match(/502/)
end
end
describe "backwards compatibility" do
it "alias RestClient::Request::Redirect to RestClient::Redirect" do
RestClient::Request::Redirect.should == RestClient::Redirect
end
it "alias RestClient::Request::Unauthorized to RestClient::Unauthorized" do
RestClient::Request::Unauthorized.should == RestClient::Unauthorized
end
it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
RestClient::Request::RequestFailed.should == RestClient::RequestFailed
end
end