Sha256: 72aebcf7d2fbd41b67162f32460aa17a889195927fea324466dc01c9ed5235b4

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

Stored size: 1.29 KB

Contents

# -*- encoding: utf-8 -*-

require 'minitest/autorun'
require 'webgen/blackboard'

class TestBlackboard < Minitest::Test

  def setup
    @blackboard = Webgen::Blackboard.new
  end

  def test_add_listener
    assert_raises(ArgumentError) { @blackboard.add_listener(:test) }
    @blackboard.add_listener(:test) { throw :called }
    assert_throws(:called) { @blackboard.dispatch_msg(:test) }

    msgs = []
    @blackboard.add_listener(:other, 'test') { msgs << 'test' }
    @blackboard.add_listener(:other, nil, :before => 'test') { msgs << 'before' }
    @blackboard.add_listener(:other, nil, :before => 'non-existing') { msgs << 'after 2' }
    @blackboard.add_listener(:other, nil, :after => 'non-existing') { msgs << 'last' }
    @blackboard.add_listener(:other, nil, :after => 'test') { msgs << 'after 1' }
    @blackboard.dispatch_msg(:other)
    assert_equal(['before', 'test', 'after 1', 'after 2', 'last'], msgs)
  end

  def test_remove_listener
    @blackboard.add_listener(:test, 'id') { throw :called }
    assert_throws(:called) { @blackboard.dispatch_msg(:test) }
    @blackboard.remove_listener(:test, 'id')
    @blackboard.dispatch_msg(:test)
  end

  def test_dispatch_msg
    @blackboard.add_listener(:test) { throw :called }
    assert_throws(:called) { @blackboard.dispatch_msg(:test) }
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
webgen-1.7.3 test/webgen/test_blackboard.rb
webgen-1.7.2 test/webgen/test_blackboard.rb
webgen-1.7.1 test/webgen/test_blackboard.rb
webgen-1.7.0 test/webgen/test_blackboard.rb
webgen-1.6.0 test/webgen/test_blackboard.rb
webgen-1.5.2 test/webgen/test_blackboard.rb
webgen-1.5.1 test/webgen/test_blackboard.rb
webgen-1.5.0 test/webgen/test_blackboard.rb
webgen-1.4.1 test/webgen/test_blackboard.rb
webgen-1.4.0 test/webgen/test_blackboard.rb
webgen-1.3.0 test/webgen/test_blackboard.rb
webgen-1.2.1 test/webgen/test_blackboard.rb
webgen-1.2.0 test/webgen/test_blackboard.rb
webgen-1.1.0 test/webgen/test_blackboard.rb
webgen-1.0.0 test/webgen/test_blackboard.rb