Adding an Observer to Test::Unit::TestResult

C

cgmjr

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top