Merge branch 'fork_exec' of git://208.76.47.125
[god.git] / test / test_meddle.rb
blobd1ea6e521dd2bddfd1c2c05705dfa060a87c82fb
1 require File.dirname(__FILE__) + '/helper'
3 class TestMeddle < Test::Unit::TestCase
4   def setup
5     Server.stubs(:new).returns(true)
6     @meddle = Meddle.new
7     God.registry.reset
8   end
9   
10   def test_should_initialize_watches_to_empty_array
11     assert_equal Hash.new, @meddle.watches
12   end
13   
14   def test_watches_should_get_stored
15     watch = nil
16     @meddle.watch { |w| watch = w }
17     
18     assert_equal 1, @meddle.watches.size
19     assert_equal watch, @meddle.watches.values.first
20     
21     assert_equal 0, @meddle.groups.size
22   end
23   
24   def test_watches_should_register_processes
25     assert_nil God.registry['foo']
26     @meddle.watch { |w| w.name = 'foo' }
27     assert_kind_of God::Process, God.registry['foo']
28   end
29   
30   def test_watches_should_get_stored_by_group
31     @meddle.watch do |w|
32       w.name = 'foo'
33       w.group = 'test'
34     end
35     
36     assert_equal({'test' => ['foo']}, @meddle.groups)
37   end
38   
39   def test_multiple_watches_should_get_stored_by_group
40     @meddle.watch do |w|
41       w.name = 'foo'
42       w.group = 'test'
43     end
44     
45     @meddle.watch do |w|
46       w.name = 'bar'
47       w.group = 'test'
48     end
49     
50     assert_equal({'test' => ['foo', 'bar']}, @meddle.groups)
51   end
53   def test_should_kick_off_a_server_instance
54     Server.expects(:new).returns(true)
55     Meddle.new
56   end
58   def test_should_take_an_options_hash
59     Server.expects(:new)
60     Meddle.new(:port => 5555)
61   end
62   
63   def test_should_allow_multiple_watches
64     @meddle.watch { |w| w.name = 'foo' }
65     
66     assert_nothing_raised do
67       @meddle.watch { |w| w.name = 'bar' }
68     end
69   end
70   
71   def test_should_disallow_duplicate_watch_names
72     @meddle.watch { |w| w.name = 'foo' }
73     
74     assert_raise AbortCalledError do
75       @meddle.watch { |w| w.name = 'foo' }
76     end
77   end
78 end