Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow integration with better_errors gem #174

Merged
merged 1 commit into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flame.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion lib/flame/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 21 additions & 1 deletion spec/integration/custom_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' }

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/integration/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

require 'rack/test'
require 'better_errors'