diff --git a/flame.gemspec b/flame.gemspec index 5fa60f6..904920d 100644 --- a/flame.gemspec +++ b/flame.gemspec @@ -44,6 +44,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'gem_toys', '~> 0.5.0' spec.add_development_dependency 'toys', '~> 0.11.0' + spec.add_development_dependency 'better_errors', '~> 2.0' spec.add_development_dependency 'codecov', '~> 0.4.3' spec.add_development_dependency 'rack-test', '~> 1.1' spec.add_development_dependency 'rspec', '~> 3.9' diff --git a/lib/flame/controller.rb b/lib/flame/controller.rb index 6c85cae..3853480 100644 --- a/lib/flame/controller.rb +++ b/lib/flame/controller.rb @@ -152,7 +152,9 @@ def not_found ## Default method for Internal Server Error, can be inherited ## @param _exception [Exception] exception from code executing ## @return [String] content of exception page - def server_error(_exception) + def server_error(exception) + raise exception if Object.const_defined?(:BetterErrors) + body default_body end diff --git a/spec/integration/custom_spec.rb b/spec/integration/custom_spec.rb index 50342da..416803c 100644 --- a/spec/integration/custom_spec.rb +++ b/spec/integration/custom_spec.rb @@ -79,8 +79,12 @@ class Application < Flame::Application subject { last_response } + let(:middlewares) { [] } + let(:app) do - CustomTest::Application.new + builder = Rack::Builder.new + middlewares.each { |middleware| builder.use middleware } + builder.run CustomTest::Application.new end describe 'foo' do @@ -200,6 +204,12 @@ class Application < Flame::Application end end + before do + hide_const 'BetterErrors' if hide_better_errors + end + + let(:hide_better_errors) { true } + context 'with regular error' do before { get '/custom/error' } @@ -215,6 +225,16 @@ class Application < Flame::Application it_behaves_like 'custom 500' end + + ## https://github.com/BetterErrors/better_errors/issues/454 + context 'when there is `BetterErrors`' do + subject(:make_request) { get '/custom/error' } + + let(:hide_better_errors) { false } + let(:middlewares) { [BetterErrors::Middleware] } + + it { expect { make_request }.to raise_error 'Test' } + end end describe 'status and headers for HEAD request' do diff --git a/spec/integration/spec_helper.rb b/spec/integration/spec_helper.rb index 11a4ed8..f0ac70c 100644 --- a/spec/integration/spec_helper.rb +++ b/spec/integration/spec_helper.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true require 'rack/test' +require 'better_errors'