Sha256: a76767913d91ffde11f0de8ac3bb960e76eee41e1417fddc5b08ef262c60d95e

Contents?: true

Size: 1.8 KB

Versions: 12

Compression:

Stored size: 1.8 KB

Contents

require 'test/unit'
require 'webgen/blackboard'

class TestBlackboard < Test::Unit::TestCase

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

  def test_add_listener
    assert_raise(ArgumentError) { @blackboard.add_listener(:test, nil) }
    assert_raise(ArgumentError) { @blackboard.add_listener(:test, 'not callable') }
    @blackboard.add_listener([:test, :other], proc { throw :called })
    assert_throws(:called) { @blackboard.dispatch_msg(:test) }
    assert_throws(:called) { @blackboard.dispatch_msg(:other) }
  end

  def test_del_listener
    listener = proc { throw :called }
    @blackboard.add_listener(:test, listener)
    assert_throws(:called) { @blackboard.dispatch_msg(:test) }
    @blackboard.del_listener(:test, listener)
    assert_nothing_thrown { @blackboard.dispatch_msg(:test) }
  end

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

  def test_add_service
    assert_raise(ArgumentError) { @blackboard.add_service(:test, 'not callable') }
    @blackboard.add_service(:test) { throw :called }
    assert_raise(RuntimeError) { @blackboard.add_service(:test, nil) }
  end

  def test_del_service
    @blackboard.add_service(:test) { throw :called }
    assert_throws(:called) { @blackboard.invoke(:test) }
    @blackboard.del_service(:test)
    assert_raise(ArgumentError) { @blackboard.invoke(:test) }
  end

  def service
    yield :test
  end

  def test_invoke
    @blackboard.add_service(:test) { throw :called }
    assert_throws(:called) { @blackboard.invoke(:test) }
    assert_raise(ArgumentError) { @blackboard.invoke(:unknown) }

    @blackboard.add_service(:other, method(:service))
    assert_throws(:test) { @blackboard.invoke(:other) {|p| throw p}}
  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.4.20080929 test/test_blackboard.rb
gettalong-webgen-0.5.5.20081001 test/test_blackboard.rb
gettalong-webgen-0.5.5.20081010 test/test_blackboard.rb
gettalong-webgen-0.5.5.20081012 test/test_blackboard.rb
gettalong-webgen-0.5.6.20081020 test/test_blackboard.rb
webgen-0.5.0 test/test_blackboard.rb
webgen-0.5.1 test/test_blackboard.rb
webgen-0.5.3 test/test_blackboard.rb
webgen-0.5.2 test/test_blackboard.rb
webgen-0.5.4 test/test_blackboard.rb
webgen-0.5.6 test/test_blackboard.rb
webgen-0.5.5 test/test_blackboard.rb