|
| 1 | +require 'spec_helper' |
| 2 | +require 'raven/integrations/rails/middleware/debug_exceptions_catcher' |
| 3 | + |
| 4 | +describe Raven::Rails::Middleware::DebugExceptionsCatcher do |
| 5 | + let(:middleware) do |
| 6 | + Class.new do |
| 7 | + def initialize(app) |
| 8 | + @app = app |
| 9 | + end |
| 10 | + |
| 11 | + def call(env) |
| 12 | + @app.call(env) |
| 13 | + rescue => e |
| 14 | + render_exception(env, e) |
| 15 | + end |
| 16 | + |
| 17 | + def render_exception(_, exception) |
| 18 | + [500, exception.message, {}] |
| 19 | + end |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + let(:app) do |
| 24 | + lambda { |_| raise "app error" } # rubocop:disable Style/Lambda |
| 25 | + end |
| 26 | + |
| 27 | + let(:env) { {} } |
| 28 | + |
| 29 | + context "using include" do |
| 30 | + before do |
| 31 | + middleware.send(:include, Raven::Rails::Middleware::OldDebugExceptionsCatcher) |
| 32 | + end |
| 33 | + |
| 34 | + it "shows the exception" do |
| 35 | + expect(middleware.new(app).call(env)).to eq([500, "app error", {}]) |
| 36 | + end |
| 37 | + |
| 38 | + it "captures the exception" do |
| 39 | + expect(Raven::Rack).to receive(:capture_exception) |
| 40 | + middleware.new(app).call(env) |
| 41 | + end |
| 42 | + |
| 43 | + context "when an error is raised" do |
| 44 | + it "shows the original exception" do |
| 45 | + allow(Raven::Rack).to receive(:capture_exception).and_raise("raven error") |
| 46 | + expect(middleware.new(app).call(env)).to eq([500, "app error", {}]) |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + context "using prepend" do |
| 52 | + before do |
| 53 | + skip "prepend not available" unless middleware.respond_to?(:prepend, true) |
| 54 | + middleware.send(:prepend, Raven::Rails::Middleware::DebugExceptionsCatcher) |
| 55 | + end |
| 56 | + |
| 57 | + it "shows the exception" do |
| 58 | + expect(middleware.new(app).call(env)).to eq([500, "app error", {}]) |
| 59 | + end |
| 60 | + |
| 61 | + it "captures the exception" do |
| 62 | + expect(Raven::Rack).to receive(:capture_exception) |
| 63 | + middleware.new(app).call(env) |
| 64 | + end |
| 65 | + |
| 66 | + context "when an error is raised" do |
| 67 | + it "shows the original exception" do |
| 68 | + allow(Raven::Rack).to receive(:capture_exception).and_raise("raven error") |
| 69 | + expect(middleware.new(app).call(env)).to eq([500, "app error", {}]) |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | +end |
0 commit comments