Sha256: d52dda6792ddd6094d6b677755fc400067ff7b996e8fe6b4fe16f17fe9713588

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

require 'action_subscriber/middleware/error_handler'

describe ActionSubscriber::Middleware::ErrorHandler do
  include_context 'action subscriber middleware env'

  subject { described_class.new(app) }

  it_behaves_like 'an action subscriber middleware'

  let(:load_error) { ::LoadError.new("Boom!") }
  let(:runtime_error) { ::RuntimeError.new("Boom!") }

  context "when an exception occurs" do
    context "LoadError" do
      before { allow(app).to receive(:call).and_raise(load_error) }
      it "calls the exception handler with a LoadError" do
        handler = ::ActionSubscriber.configuration.error_handler
        expect(handler).to receive(:call).with(load_error, env.to_h)

        subject.call(env)
      end
    end

    context "RuntimError" do
      before { allow(app).to receive(:call).and_raise(runtime_error) }
      it "calls the exception handler with a RuntimeError" do
        handler = ::ActionSubscriber.configuration.error_handler
        expect(handler).to receive(:call).with(runtime_error, env.to_h)

        subject.call(env)
      end
    end

    it "calls safe_nack after execution" do
      expect(env).to receive(:safe_nack)

      subject.call(env)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
action_subscriber-5.1.0-java spec/lib/action_subscriber/middleware/error_handler_spec.rb
action_subscriber-5.1.0 spec/lib/action_subscriber/middleware/error_handler_spec.rb
action_subscriber-5.1.0.pre-java spec/lib/action_subscriber/middleware/error_handler_spec.rb
action_subscriber-5.1.0.pre spec/lib/action_subscriber/middleware/error_handler_spec.rb