cgmjr
1/3/2006 8:07:00 PM
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.