From eff5d9aed468e8d6c4ffb103dad8e99b0a65465d Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Mon, 23 May 2011 15:31:33 +0200 Subject: Removed AS core_ext/kernel/requires as it's not used and is bad practice. --- .../connection_adapters/mysql_adapter.rb | 1 - .../connection_adapters/postgresql_adapter.rb | 1 - .../connection_adapters/sqlite_adapter.rb | 1 - .../lib/active_support/core_ext/kernel.rb | 1 - .../lib/active_support/core_ext/kernel/requires.rb | 26 ---------------------- railties/lib/rails/rack/debugger.rb | 7 +++--- railties/lib/rails/test_help.rb | 1 - 7 files changed, 3 insertions(+), 35 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/kernel/requires.rb diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index a9f4c08348..187b0b2dd8 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -1,5 +1,4 @@ require 'active_record/connection_adapters/abstract_adapter' -require 'active_support/core_ext/kernel/requires' require 'active_support/core_ext/object/blank' require 'set' diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 0a460bc086..f94d52e20e 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1,5 +1,4 @@ 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 diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index d2785b234a..39c9b6fa1d 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -1,5 +1,4 @@ require 'active_record/connection_adapters/abstract_adapter' -require 'active_support/core_ext/kernel/requires' module ActiveRecord module ConnectionAdapters #:nodoc: diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb index 01cfe7fc10..0275f4c037 100644 --- a/activesupport/lib/active_support/core_ext/kernel.rb +++ b/activesupport/lib/active_support/core_ext/kernel.rb @@ -1,5 +1,4 @@ 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' diff --git a/activesupport/lib/active_support/core_ext/kernel/requires.rb b/activesupport/lib/active_support/core_ext/kernel/requires.rb deleted file mode 100644 index 3bf46271d7..0000000000 --- a/activesupport/lib/active_support/core_ext/kernel/requires.rb +++ /dev/null @@ -1,26 +0,0 @@ -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 diff --git a/railties/lib/rails/rack/debugger.rb b/railties/lib/rails/rack/debugger.rb index 06e23db5f1..831188eeee 100644 --- a/railties/lib/rails/rack/debugger.rb +++ b/railties/lib/rails/rack/debugger.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/kernel/requires' - module Rails module Rack class Debugger @@ -8,11 +6,12 @@ module Rails 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 diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 41485c8bac..68f566274d 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -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' -- cgit v1.2.3 From 2514d65ca2b92f57b52e8027f6ab6fc8601df92f Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Mon, 23 May 2011 15:44:48 +0200 Subject: Removed the AS core_ext/kernel/debugger breakpoint method as this method is added by ruby-debug and should be left as is. Missing tests added. --- .../lib/active_support/core_ext/kernel/debugger.rb | 8 +--- activesupport/test/core_ext/kernel_test.rb | 46 ++++++++++++++++++++-- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/kernel/debugger.rb b/activesupport/lib/active_support/core_ext/kernel/debugger.rb index 692340c7c7..7516f41e0b 100644 --- a/activesupport/lib/active_support/core_ext/kernel/debugger.rb +++ b/activesupport/lib/active_support/core_ext/kernel/debugger.rb @@ -5,12 +5,6 @@ module Kernel 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 diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index ede9b0a6aa..995bc0751a 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -52,10 +52,10 @@ class KernelTest < Test::Unit::TestCase 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 @@ class KernelSuppressTest < Test::Unit::TestCase 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 -- cgit v1.2.3