How to debug unit (and other) tests?

I'm sorry if this sounds like a totally newbie question, but...

Are there good tips and resources for debugging unit tests?
Currently, I just fire up script/console using the "test" environment
and just poke around randomly until I hit upon some inspiration. But
I think there should be a better way, for example, it would be nice to
single step through a particular test case using a debugger in one
window and watching the test log in the other window.

Any tips?

Thanks.

--wpd

I'm missing something because it is not simple...

class LotTest < ActiveSupport::TestCase
...
  test "add lot to assembly" do
    debug
   ...
  end
end

When I try running this as:

$ ruby -I test test/unit/lot_test.rb -n test_add_lot_to_assembly

the test fails with:

NameError: undefined local variable or method `debug' for ...

When I try running this as:

$ rdebug -I test test/unit/lot_test.rb -n test_add_lot_to_assembly
(rdb:1) c

The test runs to completion and doesn't stop at my #debug statement.

I won't even go into my trials and tribulations trying to get this to
run under emacs...

I agree though, this should really be simple. Having said that, I
must be missing something terribly obvious.

--wpd

"debug" is for use with views, and does not stop execution.

<%= debug @foo %>

"debugger" is for actually invoking the debugger and stopping execution.

Have a look at the rails guide on debugging. Particularly the section
on ruby-debug.

Colin

Thanks. That's what I was looking for.

Now, if I could just get it to interact sanely with Emacs, I'd be a
happy camper :slight_smile:

--wpd