Skip to content

Commit

Permalink
Make debugger statements _just work_
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dchelimsky committed Nov 19, 2010
1 parent 0b278b2 commit 2466831
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 33 deletions.
5 changes: 5 additions & 0 deletions History.markdown
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions 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

Expand Down Expand Up @@ -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

Expand Down
20 changes: 5 additions & 15 deletions lib/rspec/core/configuration.rb
Expand Up @@ -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)
Expand Down
23 changes: 20 additions & 3 deletions 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
13 changes: 3 additions & 10 deletions spec/rspec/core/configuration_spec.rb
Expand Up @@ -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")
Expand Down
9 changes: 6 additions & 3 deletions 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

0 comments on commit 2466831

Please sign in to comment.