提交 a5fb1c61 编写于 作者: J José Valim

Merge pull request #1231 from joshk/ruby-debugger

Ruby debugger corrections
require 'active_record/connection_adapters/abstract_adapter'
require 'active_support/core_ext/kernel/requires'
require 'active_support/core_ext/object/blank'
require 'set'
......
require 'active_record/connection_adapters/abstract_adapter'
require 'active_support/core_ext/kernel/requires'
require 'active_support/core_ext/object/blank'
# Make sure we're using pg high enough for PGResult#values
......
require 'active_record/connection_adapters/abstract_adapter'
require 'active_support/core_ext/kernel/requires'
module ActiveRecord
module ConnectionAdapters #:nodoc:
......
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/kernel/agnostics'
require 'active_support/core_ext/kernel/requires'
require 'active_support/core_ext/kernel/debugger'
require 'active_support/core_ext/kernel/singleton_class'
......@@ -5,12 +5,6 @@ def debugger
message = "\n***** Debugger requested, but was not available (ensure ruby-debug is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n"
defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
end
end
undef :breakpoint if respond_to?(:breakpoint)
def breakpoint
message = "\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n"
defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
debugger
alias breakpoint debugger unless respond_to?(:breakpoint)
end
end
require 'active_support/core_ext/kernel/reporting'
module Kernel
# Require a library with fallback to RubyGems. Warnings during library
# loading are silenced to increase signal/noise for application warnings.
def require_library_or_gem(library_name)
silence_warnings do
begin
require library_name
rescue LoadError => cannot_require
# 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try.
begin
require 'rubygems'
rescue LoadError # => rubygems_not_installed
raise cannot_require
end
# 2. Rubygems is installed and loaded. Try to load the library again
begin
require library_name
rescue LoadError # => gem_not_installed
raise cannot_require
end
end
end
end
end
......@@ -52,10 +52,10 @@ def test_class_eval
class << o; @x = 1; end
assert_equal 1, o.class_eval { @x }
end
def test_capture
assert_equal 'STDERR', capture(:stderr) {$stderr.print 'STDERR'}
assert_equal 'STDOUT', capture(:stdout) {print 'STDOUT'}
assert_equal 'STDERR', capture(:stderr) { $stderr.print 'STDERR' }
assert_equal 'STDOUT', capture(:stdout) { print 'STDOUT' }
end
end
......@@ -73,3 +73,43 @@ def test_suppression
suppress(LoadError, ArgumentError) { raise ArgumentError }
end
end
class MockStdErr
attr_reader :output
def puts(message)
@output ||= []
@output << message
end
def info(message)
puts(message)
end
def write(message)
puts(message)
end
end
class KernelDebuggerTest < Test::Unit::TestCase
def test_debugger_not_available_message_to_stderr
old_stderr = $stderr
$stderr = MockStdErr.new
debugger
assert_match(/Debugger requested/, $stderr.output.first)
ensure
$stderr = old_stderr
end
def test_debugger_not_available_message_to_rails_logger
rails = Class.new do
def self.logger
@logger ||= MockStdErr.new
end
end
Object.const_set("Rails", rails)
debugger
assert_match(/Debugger requested/, rails.logger.output.first)
ensure
Object.send(:remove_const, "Rails")
end
end
\ No newline at end of file
require 'active_support/core_ext/kernel/requires'
module Rails
module Rack
class Debugger
......@@ -8,11 +6,12 @@ def initialize(app)
ARGV.clear # clear ARGV so that rails server options aren't passed to IRB
require_library_or_gem 'ruby-debug'
require 'ruby-debug'
::Debugger.start
::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
puts "=> Debugger enabled"
rescue Exception
rescue LoadError
puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
exit
end
......
......@@ -3,7 +3,6 @@
abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?
require 'test/unit'
require 'active_support/core_ext/kernel/requires'
require 'active_support/test_case'
require 'action_controller/test_case'
require 'action_dispatch/testing/integration'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册