GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of mojombo/god
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/auser/god.git
god / test / test_metric.rb
100644 72 lines (56 sloc) 1.791 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require File.dirname(__FILE__) + '/helper'
 
class TestMetric < Test::Unit::TestCase
  def setup
    @metric = Metric.new(stub(:interval => 10), nil)
  end
  
  # watch
  
  def test_watch
    w = stub()
    m = Metric.new(w, nil)
    assert_equal w, m.watch
  end
  
  # destination
  
  def test_destination
    d = stub()
    m = Metric.new(nil, d)
    assert_equal d, m.destination
  end
  
  # condition
  
  def test_condition_should_be_block_optional
    @metric.condition(:fake_poll_condition)
    assert_equal 1, @metric.conditions.size
  end
  
  def test_poll_condition_should_inherit_interval_from_watch_if_not_specified
    @metric.condition(:fake_poll_condition)
    assert_equal 10, @metric.conditions.first.interval
  end
  
  def test_poll_condition_should_abort_if_no_interval_and_no_watch_interval
    metric = Metric.new(stub(:name => 'foo', :interval => nil), nil)
    
    assert_abort do
      metric.condition(:fake_poll_condition)
    end
  end
  
  def test_condition_should_allow_generation_of_subclasses_of_poll_or_event
    metric = Metric.new(stub(:name => 'foo', :interval => 10), nil)
    
    assert_nothing_raised do
      metric.condition(:fake_poll_condition)
      metric.condition(:fake_event_condition)
    end
  end
  
  def test_condition_should_abort_if_not_subclass_of_poll_or_event
    metric = Metric.new(stub(:name => 'foo', :interval => 10), nil)
    
    assert_abort do
      metric.condition(:fake_condition) { |c| }
    end
  end
  
  def test_condition_should_abort_on_invalid_condition
    assert_abort do
      @metric.condition(:fake_poll_condition) { |c| c.stubs(:valid?).returns(false) }
    end
  end
  
  def test_condition_should_abort_on_no_such_condition
    assert_abort do
      @metric.condition(:invalid) { }
    end
  end
end