2008-06-11 15:31:39 -04:00
|
|
|
require File.dirname(__FILE__) + '/base'
|
|
|
|
|
2008-06-25 22:02:02 -04:00
|
|
|
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
|
|
|
|
|
2008-06-11 15:31:39 -04:00
|
|
|
describe RestClient::RequestFailed do
|
|
|
|
before do
|
2008-06-23 16:51:42 -04:00
|
|
|
@error = RestClient::RequestFailed.new
|
2008-06-11 15:31:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "extracts the error message from xml" do
|
|
|
|
@error.response = mock('response', :code => '422', :body => '<errors><error>Error 1</error><error>Error 2</error></errors>')
|
|
|
|
@error.message.should == 'Error 1 / Error 2'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores responses without xml since they might contain sensitive data" do
|
|
|
|
@error.response = mock('response', :code => '500', :body => 'Syntax error in SQL query: SELECT * FROM ...')
|
2008-06-20 22:22:19 -04:00
|
|
|
@error.message.should == 'Unknown error, HTTP status code 500'
|
2008-06-11 15:31:39 -04:00
|
|
|
end
|
2008-06-11 18:08:31 -04:00
|
|
|
|
|
|
|
it "accepts a default error message" do
|
|
|
|
@error.response = mock('response', :code => '500', :body => 'Internal Server Error')
|
|
|
|
@error.message('Custom default message').should == 'Custom default message'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't show the default error message when there's something in the xml" do
|
|
|
|
@error.response = mock('response', :code => '422', :body => '<errors><error>Specific error message</error></errors>')
|
|
|
|
@error.message('Custom default message').should == 'Specific error message'
|
|
|
|
end
|
2008-06-12 14:21:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "backwards compatibility" do
|
2008-06-23 16:50:08 -04:00
|
|
|
it "alias RestClient::Request::Redirect to RestClient::Redirect" do
|
|
|
|
RestClient::Request::Redirect.should == RestClient::Redirect
|
2008-06-12 14:21:39 -04:00
|
|
|
end
|
|
|
|
|
2008-06-23 16:50:08 -04:00
|
|
|
it "alias RestClient::Request::Unauthorized to RestClient::Unauthorized" do
|
|
|
|
RestClient::Request::Unauthorized.should == RestClient::Unauthorized
|
2008-06-12 14:21:39 -04:00
|
|
|
end
|
|
|
|
|
2008-06-23 16:50:08 -04:00
|
|
|
it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
|
|
|
|
RestClient::Request::RequestFailed.should == RestClient::RequestFailed
|
2008-06-12 14:21:39 -04:00
|
|
|
end
|
|
|
|
end
|