Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
0b278b2
commit 2466831
Showing
6 changed files
with
53 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |