1 require File.dirname(__FILE__) + '/helper'
6 def self.actions=(value)
14 def self.handler=(value)
20 class TestEventHandler < Test::Unit::TestCase
22 @h = God::EventHandler
25 def test_register_one_event
33 mock_handler.expects(:register_process).with(pid, [event])
34 @h.handler = mock_handler
36 @h.register(pid, event, &block)
37 assert_equal @h.actions, {pid => {event => block}}
40 def test_register_multiple_events_per_process
42 exit_block = lambda { puts "Hi" }
43 @h.actions = {pid => {:proc_exit => exit_block}}
46 mock_handler.expects(:register_process).with do |a, b|
48 b.to_set == [:proc_exit, :proc_fork].to_set
50 @h.handler = mock_handler
52 fork_block = lambda { puts "Forking" }
53 @h.register(pid, :proc_fork, &fork_block)
54 assert_equal @h.actions, {pid => {:proc_exit => exit_block,
55 :proc_fork => fork_block }}
59 def test_call_should_check_for_pid_and_action_before_executing
61 exit_block.expects(:call).times 1
62 @h.actions = {4445 => {:proc_exit => exit_block}}
63 @h.call(4446, :proc_exit) # shouldn't call, bad pid
64 @h.call(4445, :proc_fork) # shouldn't call, bad event
65 @h.call(4445, :proc_exit) # should call