Sha256: af13c678b5d8ae9fe5056b882dd575e6715773b46286f9068f52e7259f5efabd

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

require 'fake_sqs/catch_errors'

RSpec.describe FakeSQS::CatchErrors do

  let(:app) { double :app }
  let(:error_response) { double :error_response, :status => 500, :body => "X" }
  let(:response) { double :response, :new => error_response }
  subject(:catch_errors) { FakeSQS::CatchErrors.new(app, response: response) }

  context "when the app behaves normally" do

    let(:normal_response) { double :normal_response }
    before { allow(app).to receive(:call).and_return(normal_response) }

    it "doesn't modify normal responses" do
      expect(catch_errors.call({})).to eq normal_response
    end

  end

  context "when the app raises an exception" do

    let(:error) { RuntimeError.new("it went wrong") }
    before { allow(app).to receive(:call).and_raise(error) }

    it "cathes and processes errors" do
      expect(response).to receive(:new).with(error)
      catch_errors.call({})
    end

    it "sets the status determined by the error response" do
      allow(error_response).to receive(:status).and_return(123)
      expect(catch_errors.call({}).fetch(0)).to eq 123
    end

    it "set the body determined by the error response" do
      allow(error_response).to receive(:body).and_return("foobar")
      expect(catch_errors.call({}).fetch(2)).to eq ["foobar"]
    end

  end

end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
fake_servicebus-0.0.2 spec/unit/catch_errors_spec.rb
fake_sqs-0.4.3 spec/unit/catch_errors_spec.rb
fake_sqs-0.4.2 spec/unit/catch_errors_spec.rb
fake_sqs-0.4.1 spec/unit/catch_errors_spec.rb
fake_sqs-0.4.0 spec/unit/catch_errors_spec.rb
fake_sqs-0.3.1 spec/unit/catch_errors_spec.rb
fake_sqs-0.3.0 spec/unit/catch_errors_spec.rb
fake_sqs-0.2.0 spec/unit/catch_errors_spec.rb