Sha256: d891de21f7a6f093aa23cacb14cbdcfcecce6edda557ed7acd2cd15468f027de

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

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
    @response = mock('HTTP Response', :code => '502')
  end

  it "stores the http response on the exception" do
    begin
      raise RestClient::RequestFailed, :response
    rescue RestClient::RequestFailed => e
      e.response.should == :response
    end
  end

  it "http_code convenience method for fetching the code as an integer" do
    RestClient::RequestFailed.new(@response).http_code.should == 502
  end

  it "http_body convenience method for fetching the body (decoding when necessary)" do
    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
    RestClient::RequestFailed.new(@response).to_s.should match(/502/)
  end
end

describe RestClient::ResourceNotFound do
  it "also has the http response attached" do
    begin
      raise RestClient::ResourceNotFound, :response
    rescue RestClient::ResourceNotFound => e
      e.response.should == :response
    end
  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

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rest-client-1.3.0 spec/exceptions_spec.rb
rest-client-next-1.3.0 spec/exceptions_spec.rb