Sha256: 333886fc97dee214927364f90da16c65a90495d84f43658bf80c9010a4780988

Contents?: true

Size: 1.4 KB

Versions: 16

Compression:

Stored size: 1.4 KB

Contents

require "spec_helper"

describe Savon::HTTPError do
  let(:http_error) { Savon::HTTPError.new new_response(:code => 404, :body => "Not Found") }
  let(:no_error) { Savon::HTTPError.new new_response }

  it "inherits from Savon::Error" do
    expect(Savon::HTTPError.ancestors).to include(Savon::Error)
  end

  describe ".present?" do
    it "returns true if there was an HTTP error" do
      http = new_response(:code => 404, :body => "Not Found")
      expect(Savon::HTTPError.present? http).to be_true
    end

    it "returns false unless there was an HTTP error" do
      expect(Savon::HTTPError.present? new_response).to be_false
    end
  end

  describe "#http" do
    it "returns the HTTPI::Response" do
      expect(http_error.http).to be_a(HTTPI::Response)
    end
  end

  [:message, :to_s].each do |method|
    describe "##{method}" do
      it "returns the HTTP error message" do
        expect(http_error.send method).to eq("HTTP error (404): Not Found")
      end
    end
  end

  describe "#to_hash" do
    it "returns the HTTP response details as a Hash" do
      expect(http_error.to_hash).to eq(:code => 404, :headers => {}, :body => "Not Found")
    end
  end

  def new_response(options = {})
    defaults = { :code => 200, :headers => {}, :body => Fixture.response(:authentication) }
    response = defaults.merge options

    HTTPI::Response.new response[:code], response[:headers], response[:body]
  end

end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
savon-2.5.1 spec/savon/http_error_spec.rb
savon-2.5.0 spec/savon/http_error_spec.rb
savon_with_adapter-2.4.1 spec/savon/http_error_spec.rb
savon-2.4.0 spec/savon/http_error_spec.rb
savon-2.3.3 spec/savon/http_error_spec.rb
savon-2.3.2 spec/savon/http_error_spec.rb
savon-2.3.1 spec/savon/http_error_spec.rb
savon-ng-1.6-2.4.1 spec/savon/http_error_spec.rb
savon-ng-1.6-2.4.0 spec/savon/http_error_spec.rb
savon-2.3.0 spec/savon/http_error_spec.rb
savon-2.2.0 spec/savon/http_error_spec.rb
savon-2.1.0 spec/savon/http_error_spec.rb
savon-2.0.3 spec/savon/http_error_spec.rb
savon-2.0.2 spec/savon/http_error_spec.rb
savon-2.0.1 spec/savon/http_error_spec.rb
savon-2.0.0 spec/savon/http_error_spec.rb