1 require File.dirname(__FILE__) + '/helper'
3 class TestWatch < Test::Unit::TestCase
5 @watch = Watch.new(nil)
10 def test_new_should_have_no_behaviors
11 assert_equal [], @watch.behaviors
14 def test_new_should_have_no_metrics
15 Watch::VALID_STATES.each do |state|
16 assert_equal [], @watch.metrics[state]
20 def test_new_should_have_standard_attributes
21 assert_nothing_raised do
23 @watch.start = 'start'
25 @watch.restart = 'restart'
31 def test_new_should_have_nil_state
32 assert_equal nil, @watch.state
37 def test_mutex_should_return_the_same_mutex_each_time
38 assert_equal @watch.mutex, @watch.mutex
43 def test_behavior_should_record_behavior
45 @watch.behavior(:fake_behavior) { |b| beh = b }
46 assert_equal 1, @watch.behaviors.size
47 assert_equal beh, @watch.behaviors.first
52 def test_transition_should_abort_on_invalid_start_state
53 assert_raise AbortCalledError do
54 @watch.transition(:foo, :bar)
58 def test_transition_should_accept_all_valid_start_states
59 assert_nothing_raised do
60 Watch::VALID_STATES.each do |state|
61 @watch.transition(state, :bar) { }
66 def test_transition_should_create_and_record_a_metric_for_the_given_start_state
67 @watch.transition(:init, :start) { }
68 assert_equal 1, @watch.metrics[:init].size
73 def test_start_if_should_place_a_metric_on_up_state
75 assert_equal 1, @watch.metrics[:up].size
80 def test_restart_if_should_place_a_metric_on_up_state
82 assert_equal 1, @watch.metrics[:up].size
87 def test_canonical_hash_form_should_convert_symbol_to_hash
88 assert_equal({true => :foo}, @watch.canonical_hash_form(:foo))
91 def test_canonical_hash_form_should_convert_hash_to_hash
92 assert_equal({true => :foo}, @watch.canonical_hash_form(true => :foo))