# Proposed new feature: Drop to debugger on failed test

**URL:** <https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343>\
**Category:** Ruby\
**Created:** [November 22, 2005, 8:14am UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343 "2005-11-22T08:14:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 22, 2005, 8:14am UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/1 "2005-11-22T08:14:36Z")

</div>

I’d like to propose a simple new feature which I think could be very  
useful.

When a unit test fails, automatically raise the debugger.

Implementation should be simple - instead of just throwing errors on  
failed assertions, do a require ‘debug.rb’; raise (the exception again)

One issue I have is that this will be annoying for TDD, when we expect  
tests to fail. So there needs to be some type of switch (envariable,  
command line, etc.)

I’d appreciate comments and suggestions on this.

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 22, 2005, 8:26am UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/2 "2005-11-22T08:26:42Z")

</div>

Hi,

At Tue, 22 Nov 2005 16:12:24 +0900,  
removed\_email\_address@domain.invalid wrote in [ruby-talk:166936]:

> When a unit test fails, automatically raise the debugger.
> 
> Implementation should be simple - instead of just throwing errors on  
> failed assertions, do a require ‘debug.rb’; raise (the exception again)
> 
> One issue I have is that this will be annoying for TDD, when we expect  
> tests to fail. So there needs to be some type of switch (envariable,  
> command line, etc.)

Create autodebug.rb like as:  
module Kernel  
alias \_raise raise  
def raise(\*a)  
require “debug”  
\_raise(\*a)  
end  
end

then

$ ruby -rautodebug test\_foo.rb

or

$ RUBYOPT=rautodebug testrb foo # for directories

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 22, 2005, 5:38pm UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/3 "2005-11-22T17:38:32Z")

</div>

Or, you could simply use the breakpoint library…  
Catch your own failure and drop yourself to an IRB session…  
j.

On 11/21/05, nobuyoshi nakada [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > One issue I have is that this will be annoying for TDD, when we expect  
> > end  
> > Nobu Nakada

–  
“Remember. Understand. Believe. Yield! → [http://ruby-lang.org](http://ruby-lang.org)”

Jeff W.

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 22, 2005, 6:38pm UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/4 "2005-11-22T18:38:57Z")

</div>

On 11/22/05, Florian Groß [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have thought about doing it with ruby-breakpoint, but it turned out  
> that I would have to replace the definition of all the assertion methods  
> from Test::Unit which was a bit too much overhead.
> 
> If anyone has a better idea of how to accomplish this I would be very  
> happy to integrate it.

How about adding your own initialize to AssertionFailedError?

```
class AssertionFailedError < StandardError
  def initialize(*a)
    super(*a)
    # Do your stuff here
  end
end

```

Ryan

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 22, 2005, 7:59pm UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/5 "2005-11-22T19:59:32Z")

</div>

Ryan L. wrote:

> ```
> def initialize(*a)
> super(*a)
> # Do your stuff here
> end
> end
> 
> ```

Hm, do I have access to the type of the failed assertion from there?

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 22, 2005, 11:00pm UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/6 "2005-11-22T23:00:42Z")

</div>

Ryan L. wrote:

> > Hm, do I have access to the type of the failed assertion from there?
> 
> Not really…are you sure do you need it?
> 
> AssertionFailedError.new is only called in one place, assert\_block,  
> which is what is called by all the other assertions. So maybe you  
> could also override or alias assert\_block.

Basically it would be wonderful to have that information as part of the  
reason why the breakpoint was triggered. Last time I checked the problem  
was that as soon as the methods to through a central place that kind of  
information is already lost.

Sure, it’s not that critical a thing and I will probably still do this,  
but it would be nice to have a bit more information available.

Thanks for the information!

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [December 19, 2005, 8:25am UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/7 "2005-12-19T08:25:26Z")

</div>

nobuyoshi nakada wrote:

> Hi,
> 
> At Sat, 17 Dec 2005 15:42:18 +0900,  
> Hal F. wrote in [ruby-talk:171286]:
> 
> > I think it’s just for looks, to emphasize that it’s a string.  
> > Like String#inspect.
> 
> #dump ignores $KCODE, whereas #inspect is affected by it.

Very interesting. If I ever knew that, I forgot it.

That is the sort of information I am looking for as I learn more  
about I18N.

Hal

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 22, 2005, 6:26pm UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/8 "2005-11-22T18:26:52Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I’d like to propose a simple new feature which I think could be very  
> useful.
> 
> When a unit test fails, automatically raise the debugger.

I have thought about doing it with ruby-breakpoint, but it turned out  
that I would have to replace the definition of all the assertion methods  
from Test::Unit which was a bit too much overhead.

If anyone has a better idea of how to accomplish this I would be very  
happy to integrate it.

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 22, 2005, 8:59pm UTC](https://www.ruby-forum.com/t/proposed-new-feature-drop-to-debugger-on-failed-test/49343/9 "2005-11-22T20:59:56Z")

</div>

On 11/22/05, Florian Groß [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hm, do I have access to the type of the failed assertion from there?

Not really…are you sure do you need it?

AssertionFailedError.new is only called in one place, assert\_block,  
which is what is called by all the other assertions. So maybe you  
could also override or alias assert\_block.

But I’m not exactly sure what you are trying to do. But I can’t  
imagine something being impossible given the flexibility of the  
Test::Unit code.

Ryan
