Sha256: 7400e5e92e584a1068fa1cae6191f16ce34080a6a2e6087d7762a166947f12f8

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

require "spec_helper"

describe ShippingEasy::Http::ResponseHandler do

  let(:status) { 200 }
  let(:body) { { "order_number" => "12345" }}
  let(:response) do
    double("response",
            status: status,
            body: body.to_json)
  end

  subject { ShippingEasy::Http::ResponseHandler.new(response) }

  describe "#run" do
    context "when success" do
      specify { subject.run.should == body }
    end
    context "when request is invalid" do
      let(:status) { 400 }
      specify { expect { subject.run }.to raise_error(ShippingEasy::InvalidRequestError) }
    end
    context "when authentication fails" do
      let(:status) { 401 }
      specify { expect { subject.run }.to raise_error(ShippingEasy::AccessDeniedError) }
    end
    context "when resource cannot be found" do
      let(:status) { 404 }
      specify { expect { subject.run }.to raise_error(ShippingEasy::ResourceNotFoundError) }
    end
    context "when unexpected error occurs" do
      let(:status) { 500 }
      specify { expect { subject.run }.to raise_error(ShippingEasy::Error) }
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shipping_easy-0.7.1 spec/http/response_handler_spec.rb
shipping_easy-0.7.0 spec/http/response_handler_spec.rb
shipping_easy-0.6.1 spec/http/response_handler_spec.rb
shipping_easy-0.6.0 spec/http/response_handler_spec.rb
shipping_easy-0.5.1 spec/http/response_handler_spec.rb
shipping_easy-0.5.0 spec/http/response_handler_spec.rb
shipping_easy-0.3.2 spec/http/response_handler_spec.rb
shipping_easy-0.3.1 spec/http/response_handler_spec.rb
shipping_easy-0.3.0 spec/http/response_handler_spec.rb
shipping_easy-0.2.2 spec/http/response_handler_spec.rb
shipping_easy-0.2.1 spec/http/response_handler_spec.rb