From 246683127a176e79a2bddf2a69b8b55ccde6aabb Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Fri, 19 Nov 2010 00:28:50 -0600 Subject: [PATCH] Make debugger statements _just work_ - debugger statements work anywhere in the code, even parts that are outside RSpec's control (like before a describe declaration). - deprecated --debug/-d command line option - it doesn't do anything any more - warns if ruby-debug is not installed - only downside is for people who like to leave debugger statements around in their code --- History.markdown | 5 +++++ Upgrade.markdown | 16 ++++++++++++++-- lib/rspec/core/configuration.rb | 20 +++++--------------- lib/rspec/core/extensions/kernel.rb | 23 ++++++++++++++++++++--- spec/rspec/core/configuration_spec.rb | 13 +++---------- spec/rspec/core/kernel_extensions_spec.rb | 9 ++++++--- 6 files changed, 53 insertions(+), 33 deletions(-) diff --git a/History.markdown b/History.markdown index 756c807bd..57cbdab15 100644 --- a/History.markdown +++ b/History.markdown @@ -4,9 +4,14 @@ [full changelog](http://github.com/rspec/rspec-core/compare/v2.1.0...master) +* Deprecations + * --debug/-d on command line is deprecated and now has no effect + * Enhancements * Raise exception with helpful message when rspec-1 is loaded alongside rspec-2 (Justin Ko) + * debugger statements _just work_ as long as ruby-debug is installed + * otherwise you get warned, but not fired * Bug fixes * Make sure --fail-fast makes it across drb diff --git a/Upgrade.markdown b/Upgrade.markdown index f74e9848e..52b9e5101 100644 --- a/Upgrade.markdown +++ b/Upgrade.markdown @@ -1,4 +1,16 @@ -# New features in rspec-core-2.1 +# rspec-core-2.2 + +## Command line + +### --debug/-d is now deprecated + +This command line option is now has no effect (other than a deprecation +warning). To use the debugger, just add a `debugger` statement anywhere in your +code. As long as you have ruby-debug installed, it will just work. If you +don't, then you'll get a friendly warning telling you what's going on, but +execution will continue. + +# rspec-core-2.1 ## Command line @@ -61,7 +73,7 @@ JRuby installation to a newer release that allows the example to pass, RSpec will report it as a failure (`Expected pending '...' to fail. No Error was raised.`), so that know that you can remove the call to `pending`. -# New features in rspec-core-2.0 +# rspec-core-2.0 ### Runner diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index e28082bca..35c3bc899 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -182,21 +182,11 @@ def requires=(paths) end def debug=(bool) - return unless bool - begin - require 'ruby-debug' - rescue LoadError - raise <<-EOM - -#{'*'*50} -You must install ruby-debug to run rspec with the --debug option. - -If you have ruby-debug installed as a ruby gem, then you need to either -require 'rubygems' or configure the RUBYOPT environment variable with -the value 'rubygems'. -#{'*'*50} -EOM - end + RSpec.warn_deprecation <<-WARNING +The debug option (config.debug = true or --debug/-d on the command line) +is deprecated and no longer has any effect. This message will be removed +from future versions of RSpec. +WARNING end def line_number=(line_number) diff --git a/lib/rspec/core/extensions/kernel.rb b/lib/rspec/core/extensions/kernel.rb index ae4036149..c3c60288a 100644 --- a/lib/rspec/core/extensions/kernel.rb +++ b/lib/rspec/core/extensions/kernel.rb @@ -1,5 +1,22 @@ module Kernel - def debugger(*args) - RSpec.configuration.error_stream.puts "debugger statement ignored, use -d or --debug option to enable debugging\n#{caller(0)[1]}" - end unless respond_to?(:debugger) + def method_missing(m, *a) + if m.to_s == 'debugger' + begin + require 'ruby-debug' + debugger + rescue LoadError => e + warn <<-EOM +#{'*'*50} +The debugger statement on the following line was ignored: + + #{caller(0).detect {|l| l !~ /method_missing/}} + +To use the debugger statement, you must install ruby-debug. +#{'*'*50} +EOM + end + else + super + end + end end diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index de2623950..4949a55c0 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -531,20 +531,13 @@ def that_thing end end - describe "#debug=true" do - it "requires 'ruby-debug'" do - config.should_receive(:require).with('ruby-debug') + describe "#debug=" do + it "is deprecated" do + RSpec.should_receive(:warn_deprecation) config.debug = true end end - describe "#debug=false" do - it "does not require 'ruby-debug'" do - config.should_not_receive(:require).with('ruby-debug') - config.debug = false - end - end - describe "#output=" do it "sets the output" do output = mock("output") diff --git a/spec/rspec/core/kernel_extensions_spec.rb b/spec/rspec/core/kernel_extensions_spec.rb index dc59d7eec..a8c168d96 100644 --- a/spec/rspec/core/kernel_extensions_spec.rb +++ b/spec/rspec/core/kernel_extensions_spec.rb @@ -1,9 +1,12 @@ require 'spec_helper' describe "extensions" do - describe "debugger" do - it "is defined on Kernel" do - Kernel.should respond_to(:debugger) + describe "#debugger" do + it "warns if ruby-debug is not installed" do + object = Object.new + object.should_receive(:warn).with(/debugger .* ignored/) + object.stub(:require) { raise LoadError } + object.method_missing(:debugger) end end end