Using RSpec in the Ruby debugger


#1

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 methodcontext_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


#2

On 8 feb, 23:59, “Greg H.” 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/