Sha256: d3e0860bcfb53da499d2f8575a1a4613cdce69025954729b8f5b351e47e8ee5e

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

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

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

15 entries across 15 versions & 3 rubygems

Version Path
gettalong-webgen-0.5.7.20090227 test/test_blackboard.rb
gettalong-webgen-0.5.8.20090507 test/test_blackboard.rb
gettalong-webgen-0.5.9.20090620 test/test_blackboard.rb
gettalong-webgen-0.5.9.20090626 test/test_blackboard.rb
thewoolleyman-webgen-0.5.8.20090419 test/test_blackboard.rb
webgen-0.5.17 test/test_blackboard.rb
webgen-0.5.15 test/test_blackboard.rb
webgen-0.5.14 test/test_blackboard.rb
webgen-0.5.13 test/test_blackboard.rb
webgen-0.5.12 test/test_blackboard.rb
webgen-0.5.11 test/test_blackboard.rb
webgen-0.5.10 test/test_blackboard.rb
webgen-0.5.9 test/test_blackboard.rb
webgen-0.5.7 test/test_blackboard.rb
webgen-0.5.8 test/test_blackboard.rb