Sha256: 27ee0f54ffba730e98bcdcccaeabb16fe7ef50d8e7dc4b7d1b10d42577857ec7

Contents?: true

Size: 1.84 KB

Versions: 67

Compression:

Stored size: 1.84 KB

Contents

require File.dirname(__FILE__) + '/helper'

module God
  class EventHandler
    
    def self.actions=(value)
      @@actions = value
    end
    
    def self.actions
      @@actions
    end
    
    def self.handler=(value)
      @@handler = value
    end
  end
end

class TestEventHandler < Test::Unit::TestCase
  def setup
    @h = God::EventHandler
  end
    
  def test_register_one_event
    pid = 4445
    event = :proc_exit
    block = lambda {
      puts "Hi"
    }
    
    mock_handler = mock()
    mock_handler.expects(:register_process).with(pid, [event])
    @h.handler = mock_handler
    
    @h.register(pid, event, &block)
    assert_equal @h.actions, {pid => {event => block}}
  end
  
  def test_register_multiple_events_per_process
    pid = 4445
    exit_block = lambda { puts "Hi" }
    @h.actions = {pid => {:proc_exit => exit_block}}
    
    mock_handler = mock()
    mock_handler.expects(:register_process).with do |a, b|
      a == pid &&
      b.to_set == [:proc_exit, :proc_fork].to_set
    end
    @h.handler = mock_handler
    
    fork_block = lambda { puts "Forking" }
    @h.register(pid, :proc_fork, &fork_block)
    assert_equal @h.actions, {pid => {:proc_exit => exit_block,
                                     :proc_fork => fork_block }}
  end
  
  # JIRA PLATFORM-75
  def test_call_should_check_for_pid_and_action_before_executing
    exit_block = mock()
    exit_block.expects(:call).times 1
    @h.actions = {4445 => {:proc_exit => exit_block}}
    @h.call(4446, :proc_exit) # shouldn't call, bad pid
    @h.call(4445, :proc_fork) # shouldn't call, bad event
    @h.call(4445, :proc_exit) # should call
  end
  
  def teardown
    # Reset handler
    @h.actions = {}
    @h.load
  end
end

class TestEventHandlerOperational < Test::Unit::TestCase
  def test_operational
    God::EventHandler.start
    assert God::EventHandler.loaded?
  end
end

Version data entries

67 entries across 67 versions & 21 rubygems

Version Path
dguettler-god-0.7.13.2 test/test_event_handler.rb
dguettler-god-0.7.13.3 test/test_event_handler.rb
dosire-god-0.7.10 test/test_event_handler.rb
dosire-god-0.7.12 test/test_event_handler.rb
dosire-god-0.7.9 test/test_event_handler.rb
dunedain289-god-0.7.12.1 test/test_event_handler.rb
dustin-god-0.7.7.1 test/test_event_handler.rb
eric-god-0.7.10 test/test_event_handler.rb
eric-god-0.7.11 test/test_event_handler.rb
eric-god-0.7.12 test/test_event_handler.rb
eric-god-0.7.14 test/test_event_handler.rb
eric-god-0.7.7 test/test_event_handler.rb
fotonauts-god-0.7.10 test/test_event_handler.rb
fotonauts-god-0.7.12 test/test_event_handler.rb
gohanlonllc-god-0.7.9 test/test_event_handler.rb
gordoncww-god-0.7.11.1 test/test_event_handler.rb
jreynolds-god-0.7.13 test/test_event_handler.rb
jwilkins-god-0.7.9 test/test_event_handler.rb
mathieuravaux-god-0.7.11 test/test_event_handler.rb
mojombo-god-0.7.10 test/test_event_handler.rb