test/obs_test.rb in openwferu-0.9.12 vs test/obs_test.rb in openwferu-0.9.12.863
- old
+ new
@@ -25,10 +25,12 @@
#end
class Observed
include OpenWFE::Observable
+ attr_reader :observers
+
def initialize
super
@observers = {}
end
@@ -108,8 +110,33 @@
assert_equal $s, 9
$s = nil
observed.onotify "channelZ", :nothing
assert_nil $s
+ end
+
+ def test_2
+
+ observed = Observed.new
+
+ o1 = observed.add_observer :channel0 do
+ puts "whatever"
+ end
+ o2 = observed.add_observer :channel0 do
+ puts "whatever"
+ end
+
+ assert_equal observed.observers.size, 1
+ assert_equal observed.observers[:channel0].size, 2
+
+ observed.remove_observer o1
+
+ assert_equal observed.observers.size, 1
+ assert_equal observed.observers[:channel0].size, 1
+
+ observed.remove_observer o2
+
+ assert_equal observed.observers.size, 1
+ assert_equal observed.observers[:channel0].size, 0
end
end