tighten up Hub and add comments
[god.git] / test / test_conditions_tries.rb
blob0b1fc2c48bb8ce13159e4a867280d4b82fcc2721
1 require File.dirname(__FILE__) + '/helper'
3 class TestConditionsTries < Test::Unit::TestCase
4   # valid?
5   
6   def test_valid_should_return_false_if_times_not_set
7     c = Conditions::Tries.new
8     c.watch = stub(:name => 'foo')
9     no_stdout { assert !c.valid? }
10   end
11 end
14 class TestConditionsTries < Test::Unit::TestCase
15   def setup
16     @c = Conditions::Tries.new
17     @c.times = 3
18     @c.prepare
19   end
20   
21   # prepare
22   
23   def test_prepare_should_create_timeline
24     assert 3, @c.instance_variable_get(:@timeline).instance_variable_get(:@max_size)
25   end
26   
27   # test
28   
29   def test_test_should_return_true_if_called_three_times_within_one_second
30     assert !@c.test
31     assert !@c.test
32     assert @c.test
33   end
34   
35   # reset
36   
37   def test_test_should_return_false_on_fourth_call_if_called_three_times_within_one_second
38     3.times { @c.test }
39     @c.reset
40     assert !@c.test
41   end
42 end
45 class TestConditionsTriesWithin < Test::Unit::TestCase
46   def setup
47     @c = Conditions::Tries.new
48     @c.times = 3
49     @c.within = 1.seconds
50     @c.prepare
51   end
52   
53   # test
54   
55   def test_test_should_return_true_if_called_three_times_within_one_second
56     assert !@c.test
57     assert !@c.test
58     assert @c.test
59   end
60   
61   def test_test_should_return_false_if_called_three_times_within_two_seconds
62     assert !@c.test
63     assert !@c.test
64     assert sleep(1.1)
65     assert !@c.test
66   end
67 end