Sha256: 20cd5ad54bf610fbcb599e3b6ab2b4e6492264f84a76ef8aefc9955f81bcf6b7
Contents?: true
Size: 1.84 KB
Versions: 11
Compression:
Stored size: 1.84 KB
Contents
require 'spec_helper' describe Protobuf::Rpc::Middleware::ExceptionHandler do let(:app) { Proc.new { |env| env } } let(:env) { Protobuf::Rpc::Env.new } subject { described_class.new(app) } describe "#call" do it "calls the stack" do expect(app).to receive(:call).with(env) subject.call(env) end it "returns the env" do expect(subject.call(env)).to eq env end context "when exceptions occur" do let(:encoded_error) { error.encode } let(:error) { Protobuf::Rpc::MethodNotFound.new('Boom!') } before { allow(app).to receive(:call).and_raise(error, 'Boom!') } it "rescues exceptions" do expect { subject.call(env) }.not_to raise_exception end context "when exception is a Protobuf error" do it "does not wrap the exception in a generic Protobuf error" do stack_env = subject.call(env) # Can't compare the error instances because the response has been # raised and thus has a backtrace while the error does not. expect(stack_env.response.class).to eq error.class end it "encodes the response" do stack_env = subject.call(env) expect(stack_env.encoded_response).to eq encoded_error end end context "when exception is not a Protobuf error" do let(:encoded_error) { error.encode } let(:error) { Protobuf::Rpc::RpcFailed.new('Boom!') } before { allow(app).to receive(:call).and_raise(RuntimeError, 'Boom!') } it "wraps the exception in a generic Protobuf error" do stack_env = subject.call(env) expect(stack_env.response).to eq error end it "encodes the wrapped exception" do stack_env = subject.call(env) expect(stack_env.encoded_response).to eq encoded_error end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems