Sha256: 7d8a1c0f43327dc6ec5dc1a77c0645bedf6bc012c36caa390199b7c11f301c8f

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

require 'test_helper'
require 'apotomo/proc_event_handler'

class EventHandlerTest < Test::Unit::TestCase
  include Apotomo::TestCaseMethods::TestController
  
  context "an abstract EventHandler" do
    should "push nil to root's ordered page_updates when #call'ed" do
      @mum = mouse
        @mum << mouse_mock(:kid)
      
      assert_equal 0, @mum.page_updates.size
      
      [@mum, @mum[:kid], @mum].each do |source|
        Apotomo::EventHandler.new.call(Apotomo::Event.new(:squeak, source))
      end
      
      # order matters:
      assert_equal 3, @mum.page_updates.size
      assert_equal 0, @mum[:kid].page_updates.size
      assert_equal(nil, @mum.page_updates[0])
      assert_equal(nil, @mum.page_updates[1])
      assert_equal(nil, @mum.page_updates[2])
    end
  end
  
  
  
  def test_invoke_to_s
    h = Apotomo::InvokeEventHandler.new
    h.widget_id = :widget_id
    h.state     = :my_state
    assert_equal "InvokeEventHandler:widget_id#my_state", h.to_s
  end
  
  def test_proc_to_s
    h = Apotomo::ProcEventHandler.new
    h.proc = :my_method
    assert_equal "ProcEventHandler:my_method", h.to_s
  end
  
  def test_constructor_for_proc
    h = Apotomo::ProcEventHandler.new
    assert_nil h.proc
    h = Apotomo::ProcEventHandler.new(:proc => :method)
    assert_equal :method, h.proc
  end
  
  def test_constructor_for_invoke
    h = Apotomo::InvokeEventHandler.new
    assert_nil h.widget_id
    assert_nil h.state
    h = Apotomo::InvokeEventHandler.new(:widget_id => :widget, :state => :state)
    assert_equal :widget, h.widget_id
    assert_equal :state,  h.state
  end
  
  def test_equal
    h1 = Apotomo::ProcEventHandler.new(:proc => :run)
    h2 = Apotomo::ProcEventHandler.new(:proc => :run)
    h3 = Apotomo::ProcEventHandler.new(:proc => :walk)
    
    assert h1 == h2
    assert h1 != h3
  end
  
  ### TODO: test #call
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apotomo-1.2.3 test/event_handler_test.rb
apotomo-1.2.2 test/event_handler_test.rb
apotomo-1.2.1 test/event_handler_test.rb
apotomo-1.2.0 test/event_handler_test.rb