Sha256: 3cdfab7f1b837a721fdd29107037097352d794625ef712d90c33e3020fa097ed

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

#
# Testing OpenWFE
#
# John Mettraux at openwfe.org
#
# Sun Oct 29 16:18:25 JST 2006
#

require 'test/unit'

require 'openwfe/util/observable'


#
# testing the observer module (mixin)
#

class ObsTest < Test::Unit::TestCase

    #def setup
    #end

    #def teardown
    #end

    class Observed
        include OpenWFE::Observable

        def initialize
            super
            @observers = {}
        end

        public :onotify
    end

    def test_0

        $s = nil

        observed = Observed.new

        observed.add_observer :channel0 do
            $s = 0
        end

        observer1 = Object.new
        class << observer1
            def call channel, *args
                $s = 1
            end
        end
        observed.add_observer :channel1, observer1

        observer2 = lambda do |channel, args|
            $s = 2
        end
        observed.add_observer :channel2, observer2

        observed.onotify :channel0, :nothing
        assert_equal $s, 0

        observed.onotify :channel1, :nothing
        assert_equal $s, 1

        observed.onotify :channel2, :nothing
        assert_equal $s, 2

        $s = nil

        observed.remove_observer observer2, :channel99

        observed.onotify :channel2, :nothing
        assert_equal $s, 2

        $s = nil

        observed.remove_observer observer2

        observed.onotify :channel2, :nothing
        assert_nil $s

        $s = nil

        observed.remove_observer observer1, :channel1

        observed.onotify :channel1, :nothing
        assert_nil $s
    end


    def test_1

        $s = nil

        observed = Observed.new

        observed.add_observer :channel0 do
            $s = 0
        end
        observed.add_observer "channel[0-9]+" do
            $s = 9
        end

        $s = nil
        observed.onotify "channel2", :nothing
        assert_equal $s, 9

        $s = nil
        observed.onotify "channelZ", :nothing
        assert_nil $s
    end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openwferu-0.9.12 test/obs_test.rb
openwferu-0.9.11 test/obs_test.rb