aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-23 06:48:05 -0700
committerJosé Valim <jose.valim@gmail.com>2011-05-23 06:48:05 -0700
commita5fb1c61755f03a8c75b0a434fb2aca57502293b (patch)
tree093d94f72e157c71baaf8a3e749f4e4c20781bfd
parent5c3f3f10babe01ec0b6ae04a8846b5598d107926 (diff)
parent2514d65ca2b92f57b52e8027f6ab6fc8601df92f (diff)
downloadrails-a5fb1c61755f03a8c75b0a434fb2aca57502293b.tar.gz
rails-a5fb1c61755f03a8c75b0a434fb2aca57502293b.tar.bz2
rails-a5fb1c61755f03a8c75b0a434fb2aca57502293b.zip
Merge pull request #1231 from joshk/ruby-debugger
Ruby debugger corrections
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/kernel.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/kernel/debugger.rb8
-rw-r--r--activesupport/lib/active_support/core_ext/kernel/requires.rb26
-rw-r--r--activesupport/test/core_ext/kernel_test.rb46
-rw-r--r--railties/lib/rails/rack/debugger.rb7
-rw-r--r--railties/lib/rails/test_help.rb1
9 files changed, 47 insertions, 45 deletions
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/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/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/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
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'