| Class | ObservableTest |
| In: |
lib/observable.rb
|
| Parent: | Test::Unit::TestCase |
# File lib/observable.rb, line 126 def test_notifier_methods_visibility fm = ObservableMethodsVisibilityFoo.new assert_raises(NoMethodError) { fm.add_observer(Object.new) } assert_raises(NoMethodError) { fm.notify_observer(Object.new) } assert_raises(NoMethodError) { fm.list_observer } assert_raises(NoMethodError) { fm.changed? } end
Tests
# File lib/observable.rb, line 91 def test_simple o1 = Obsv.new o2 = Obsv.new n = Notify.new(o1, o2) assert_equal(2, n.count_observers, 'bad number of observers') assert(n.observer?(o1)) n.changed n.notify_observers('all') assert_equal('all', o1.last_msg, 'bad msg o1 1') assert_equal('all', o2.last_msg, 'bad msg o2 1') l = n.list_observers assert_equal(o1, l[0], 'o1 is not at the right place in the list') assert_equal(o2, l[1], 'o2 is not at the right place in the list') n.changed n.notify_observer(o1, 'o1') assert_equal('o1', o1.last_msg, 'bad msg o1 2') assert_equal('all', o2.last_msg, 'bad msg o2 2') n.changed n.notify_observer(o2, 'o2') assert_equal('o1', o1.last_msg, 'bad msg o1 3') assert_equal('o2', o2.last_msg, 'bad msg o2 3') n.changed n.notify_observer(o1, 'new_all') n.changed n.notify_observer(o2, 'new_all') assert_equal('new_all', o1.last_msg, 'bad msg o1 4') assert_equal('new_all', o2.last_msg, 'bad msg o2 4') end