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'
28 def test_start_if_should_modify_action_within_scope
29 assert_equal nil, @watch.instance_variable_get(:@action)
30 @watch.start_if do |w|
31 assert_equal :start, @watch.instance_variable_get(:@action)
33 assert_equal nil, @watch.instance_variable_get(:@action)
36 def test_restart_if_should_modify_action_within_scope
37 assert_equal nil, @watch.instance_variable_get(:@action)
38 @watch.restart_if do |w|
39 assert_equal :restart, @watch.instance_variable_get(:@action)
41 assert_equal nil, @watch.instance_variable_get(:@action)
46 def test_start_condition_should_record_condition_in_correct_list
48 @watch.start_if do |w|
49 w.condition(:fake_condition) { |c| cond = c }
51 assert_equal 1, @watch.conditions[:start].size
52 assert_equal cond, @watch.conditions[:start].first
55 def test_restart_condition_should_record_condition_in_correct_list
57 @watch.restart_if do |w|
58 w.condition(:fake_condition) { |c| cond = c }
60 assert_equal 1, @watch.conditions[:restart].size
61 assert_equal cond, @watch.conditions[:restart].first
64 def test_condition_called_from_outside_if_block_should_raise
65 assert_raise AbortCalledError do
66 @watch.condition(:fake_condition) { |c| cond = c }
70 def test_condition_should_be_block_optional
71 @watch.start_if do |w|
74 assert_equal 1, @watch.conditions[:start].size
79 def test_behavior_should_record_behavior
81 @watch.behavior(:fake_behavior) { |b| beh = b }
82 assert_equal 1, @watch.behaviors.size
83 assert_equal beh, @watch.behaviors.first