minor test fixes
[god.git] / test / test_conditions_tries.rb
blob12add4814d647a102d5ffe24a18744385552c704
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   def test_test_should_return_false_on_fourth_call_if_called_three_times_within_one_second
36     3.times { @c.test }
37     assert !@c.test
38   end
39 end
42 class TestConditionsTriesWithin < Test::Unit::TestCase
43   def setup
44     @c = Conditions::Tries.new
45     @c.times = 3
46     @c.within = 1.seconds
47     @c.prepare
48   end
49   
50   # test
51   
52   def test_test_should_return_true_if_called_three_times_within_one_second
53     assert !@c.test
54     assert !@c.test
55     assert @c.test
56   end
57   
58   def test_test_should_return_false_if_called_three_times_within_two_seconds
59     assert !@c.test
60     assert !@c.test
61     assert sleep(1.1)
62     assert !@c.test
63   end
64 end