1 require File.dirname(__FILE__) + '/helper'
3 class TestWatch < Test::Unit::TestCase
5 @watch = Watch.new(nil)
8 def test_should_have_empty_start_conditions
9 assert_equal [], @watch.conditions[:start]
12 def test_should_have_empty_restart_conditions
13 assert_equal [], @watch.conditions[:restart]
16 def test_should_have_standard_attributes
17 assert_nothing_raised do
19 @watch.start = 'start'
21 @watch.restart = 'restart'
29 def test_start_if_should_modify_action_within_scope
30 assert_equal nil, @watch.instance_variable_get(:@action)
31 @watch.start_if do |w|
32 assert_equal :start, @watch.instance_variable_get(:@action)
34 assert_equal nil, @watch.instance_variable_get(:@action)
37 def test_restart_if_should_modify_action_within_scope
38 assert_equal nil, @watch.instance_variable_get(:@action)
39 @watch.restart_if do |w|
40 assert_equal :restart, @watch.instance_variable_get(:@action)
42 assert_equal nil, @watch.instance_variable_get(:@action)
47 def test_start_condition_should_record_condition_in_correct_list
50 @watch.start_if do |w|
51 w.condition(:fake_poll_condition) { |c| cond = c }
53 assert_equal 1, @watch.conditions[:start].size
54 assert_equal cond, @watch.conditions[:start].first
57 def test_restart_condition_should_record_condition_in_correct_list
60 @watch.restart_if do |w|
61 w.condition(:fake_poll_condition) { |c| cond = c }
63 assert_equal 1, @watch.conditions[:restart].size
64 assert_equal cond, @watch.conditions[:restart].first
67 def test_condition_called_from_outside_if_block_should_raise
68 assert_raise AbortCalledError do
69 @watch.condition(:fake_poll_condition) { |c| cond = c }
73 def test_condition_should_be_block_optional
75 @watch.start_if do |w|
78 assert_equal 1, @watch.conditions[:start].size
81 def test_poll_condition_should_inherit_interval_from_watch_if_not_specified
83 @watch.start_if do |w|
84 w.condition(:fake_poll_condition)
86 assert_equal 27, @watch.conditions[:start].first.interval
89 def test_poll_condition_should_abort_if_no_interval_and_no_watch_interval
90 assert_raise AbortCalledError do
91 @watch.start_if do |w|
92 w.condition(:fake_poll_condition)
97 def test_condition_should_allow_generation_of_subclasses_of_poll_or_event
99 assert_nothing_raised do
100 @watch.start_if do |w|
101 w.condition(:fake_poll_condition)
102 w.condition(:fake_event_condition)
107 def test_condition_should_abort_if_not_subclass_of_poll_or_event
108 assert_raise AbortCalledError do
109 @watch.start_if do |w|
110 w.condition(:fake_condition) { |c| }
117 def test_behavior_should_record_behavior
119 @watch.behavior(:fake_behavior) { |b| beh = b }
120 assert_equal 1, @watch.behaviors.size
121 assert_equal beh, @watch.behaviors.first