config: add debug_mode option.

Add a debug mode option. This is useful when debugging failed tests.

Debug mode disables parallel testing so you can set breakpoints in tests
with binding.pry (normally parallel testing makes it hard to set
breakpoints).

Debug mode also disables global exception handling for controllers. This
lets exceptions bubble up to the console during controller tests
(normally exceptions are swallowed by the controller, which prevents you
from seeing backtraces in failed controller tests).
This commit is contained in:
evazion
2020-12-23 17:51:53 -06:00
parent a084da2dbe
commit a947a10c53
3 changed files with 17 additions and 4 deletions

View File

@@ -88,6 +88,8 @@ class ApplicationController < ActionController::Base
end
def rescue_exception(exception)
return if Danbooru.config.debug_mode
case exception
when ActionView::Template::Error
rescue_exception(exception.cause)

View File

@@ -52,6 +52,15 @@ module Danbooru
"_danbooru2_session"
end
# Debug mode does some things to make testing easier. It disables parallel
# testing and it replaces Danbooru's custom exception page with the default
# Rails exception page. This is only useful during development and testing.
#
# Usage: `DANBOORU_DEBUG_MODE=true bin/rails test
def debug_mode
false
end
def source_code_url
"https://github.com/danbooru/danbooru"
end

View File

@@ -30,11 +30,13 @@ class ActiveSupport::TestCase
mock_post_version_service!
mock_pool_version_service!
parallelize
parallelize_setup do |worker|
Rails.application.load_seed
unless Danbooru.config.debug_mode
parallelize
parallelize_setup do |worker|
Rails.application.load_seed
SimpleCov.command_name "#{SimpleCov.command_name}-#{worker}"
SimpleCov.command_name "#{SimpleCov.command_name}-#{worker}"
end
end
parallelize_teardown do |worker|