# Adding an Observer to Test::Unit::TestResult

**URL:** <https://www.ruby-forum.com/t/adding-an-observer-to-test-testresult/51579>\
**Category:** Ruby\
**Created:** [January 3, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/adding-an-observer-to-test-testresult/51579 "2006-01-03T21:09:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cgmjr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cgmjr](https://www.ruby-forum.com/u/cgmjr)\
**Post date:** [January 3, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/adding-an-observer-to-test-testresult/51579/1 "2006-01-03T21:09:35Z")

</div>

Can anyone share with me on how you would subscribe  
to Test::Unit::TestResult with a Observer? Currently I have working  
this, but it seems clumsy to me:  
require ‘test/unit’  
require ‘enumerator’

class Report\_failure

```
def initialize
    tresultinstance=ObjectSpace.enum_for( :each_object,

```

Test::Unit::TestResult ).to\_a  
tresultinstance[0].add\_listener(Test::Unit::TestResult::FAULT,  
&method(:notify\_failure))  
end

```
def notify_failure(failure)
    printf "Observed failure =%s \n", failure.long_display
end

```

end

But in Ed. 1 of Dave, Chad, and Andy’s book there’s the cool  
add\_observer bit, as in:

…  
def initialize(ticker, limit)  
@limit = limit  
ticker.add\_observer(self) # all warners are observers  
end  
…

I need some style hints. Has add\_observer been deprecated in 1.8.2?

Many thanks!  
g.
