# Using RSpec in the Ruby debugger

**URL:** <https://www.ruby-forum.com/t/using-rspec-in-the-ruby-debugger/84984>\
**Category:** Ruby\
**Created:** [February 9, 2007, 12:01am UTC](https://www.ruby-forum.com/t/using-rspec-in-the-ruby-debugger/84984 "2007-02-09T00:01:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [February 9, 2007, 12:01am UTC](https://www.ruby-forum.com/t/using-rspec-in-the-ruby-debugger/84984/1 "2007-02-09T00:01:24Z")

</div>

Is it possible to run RSpec specs from inside the Ruby debugger? I’ve  
got a failing spec and I would like to single-step through the failing  
code so as to figure out what’s going on. The alternative is not very  
attractive: sprinkling my code with logging statements.

The specs run fine from the command line using “rake spec”; they also  
run fine using the “spec” commandline tool; and the single file which  
contains the failing spec also runs fun when executed using “ruby spec/  
the\_file\_spec.rb”.

When I say “runs fine”, I mean the specs run, no extraneous error  
messages are printed, and one of them fails.

But when I try to run the spec under the debugger using “ruby -r debug  
spec/the\_file\_spec.rb” I get dozens of extraneous error messages which  
make it totally impractical if not impossible to single-step. I set a  
breakpoint on the line where I want to start inspecting things but I  
never get there because I have to wade through hundreds or even  
thousands of messages like this:

/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.5.1/lib/spec/runner/  
context\_eval.rb:116: `undefined method`context\_setup’ for class  
`Object’’ (NameError)

Or this:

`can’t clone NilClass’ (TypeError)

Or this:

`can’t clone Fixnum’ (TypeError)

Or this:

`can’t modify literal regexp’ (SecurityError)

This only happens under the debugger. A Google search for “rspec  
debugger” yields only one hit that doesn’t seem relevant. Has anyone  
successfully run their RSpec specs under the debugger?

Thanks for any help you can give,  
Greg

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [February 9, 2007, 1:00pm UTC](https://www.ruby-forum.com/t/using-rspec-in-the-ruby-debugger/84984/2 "2007-02-09T13:00:26Z")

</div>

On 8 feb, 23:59, “Greg H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is it possible to run RSpec specs from inside the Ruby debugger?

Ok, for the record, before I got to the bottom of this problem I  
thought I’d try using ruby-debug instead and see if the same problems  
exist. Curiously, everything works perfectly under ruby-debug. It  
works great and I was able to zero-in on the cause of my failing spec,  
single-stepping through the problematic section and seeing what was  
really going on under the covers. I am sure that without the debugger  
I could have wasted days trying to figure out the cause, but under the  
debugger it was a matter of about half an hour’s analysis.

> A Google search for “rspec  
> debugger” yields only one hit that doesn’t seem relevant. Has anyone  
> successfully run their RSpec specs under the debugger?

To clarify, the “one hit” I got was not from searching Google in  
general, but searching just comp.lang.ruby… A wider search of the  
web is what turned up references that led me to ruby-debug.

[http://rubyforge.org/projects/ruby-debug/](http://rubyforge.org/projects/ruby-debug/)
