Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wjordan committed Aug 16, 2018
1 parent 1ef23fb commit 0e15376
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/lograge/rails_ext/action_dispatch/debug_exceptions.rb
@@ -1,4 +1,8 @@
require 'action_dispatch/middleware/debug_exceptions'
require 'action_dispatch'

# Require needed to workaround bug:
# https://github.com/rails/rails/issues/33634
require 'active_support/core_ext/hash/indifferent_access'

module Lograge
module DebugExceptions
Expand Down
53 changes: 53 additions & 0 deletions spec/lograge_spec.rb
Expand Up @@ -212,4 +212,57 @@ def current_user_id
end
end
end

describe 'handling exceptions' do
let(:app_config) do
double(config:
ActiveSupport::OrderedOptions.new.tap do |config|
config.action_dispatch = double(rack_cache: false)
config.lograge = ActiveSupport::OrderedOptions.new
end)
end
let(:debug_exceptions) do
ActionDispatch::DebugExceptions.new(->(_) { raise })
end
let(:output) { StringIO.new }
let(:logger) { Logger.new(output) }
let(:env) do
Rack::MockRequest.env_for(
'',
'action_dispatch.show_detailed_exceptions' => true,
'action_dispatch.logger' => logger
)
end

before do
Lograge.setup(app_config)
Lograge.logger = logger
end

it 'adds formatted exception log' do
debug_exceptions.call(env)
expect(output.string).to match(/status=500 error='RuntimeError: '/)
end

it 'removes original exception log' do
debug_exceptions.call(env)
expect(output.string).not_to match(/FATAL -- : RuntimeError/)
end

context 'when keep_original_rails_log is true' do
before do
app_config.config.lograge.keep_original_rails_log = true
end

it 'adds formatted exception log' do
debug_exceptions.call(env)
expect(output.string).to match(/status=500 error='RuntimeError: '/)
end

it 'keeps original exception log' do
debug_exceptions.call(env)
expect(output.string).to match(/FATAL -- : RuntimeError/)
end
end
end
end

0 comments on commit 0e15376

Please sign in to comment.