Sha256: 66625e3a7cbf044d11499fced1a16df86bd507b204be12495f0b6a6905409beb

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

require 'rubygems'
require 'test/unit'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'ceml'

class Test::Unit::TestCase
  DRIVER = CEML::Driver.new

  def play script = nil
    @iid = script && DRIVER.start(nil, script)
    yield
    CEML::Driver::JUST_SAID.clear
    CEML::Driver::PLAYERS.clear
    CEML::Driver::INCIDENTS.clear
  end

  def scriptfam *scripts
    fam_id = gen_code
    scripts.each do |script|
      script = CEML.parse(:script, script) if String === script
      DRIVER.add_script fam_id, script
    end
    fam_id
  end

  def ping s, candidate
    DRIVER.ping_all s, candidate
  end

  def says id, str
    iid = CEML::Driver::INCIDENTS.keys.find do |iid|
      CEML::Driver::PLAYERS[iid].find{ |p| p[:id] == id }
    end
    DRIVER.post iid, :id => id, :received => str
  end

  def player id, *roles
    DRIVER.post @iid, :id => id, :roles => roles
  end

  def roll
    DRIVER.post @iid
  end

  def asked id, rx
    assert p = CEML::Driver::JUST_SAID[id]
    assert_equal :ask, p[:said]
    assert_match rx, p[:q]
    CEML::Driver::JUST_SAID.delete id
  end

  def silent id
    assert !CEML::Driver::JUST_SAID[id]
  end

  def told id, rx
    assert p = CEML::Driver::JUST_SAID[id]
    assert_match rx, p[:msg]
    CEML::Driver::JUST_SAID.delete id
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ceml-0.7.3 test/helper.rb
ceml-0.7.2 test/helper.rb
ceml-0.7.1 test/helper.rb
ceml-0.7.0 test/helper.rb