Skip to content

Commit

Permalink
Allow integration with better_errors gem
Browse files Browse the repository at this point in the history
More info here: BetterErrors/better_errors#454

Example:

```ruby
# config.ru

require 'better_errors'
use BetterErrors::Middleware
BetterErrors.application_root = __dir__
```

(I hope I'll not forget to add this to the wiki)
  • Loading branch information
AlexWayfer committed Feb 6, 2021
1 parent 8c1cfa1 commit 789c103
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
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'

0 comments on commit 789c103

Please sign in to comment.