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

53 lines
1.9 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
before do
@error = RestClient::RequestFailed.new
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 ...')
@error.message.should == 'Unknown error, HTTP status code 500'
end
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
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