PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/test/test_conditions_tries.rb

https://github.com/Susong/god
Ruby | 67 lines | 47 code | 15 blank | 5 comment | 0 complexity | 89c766113ec6fde4dee9161ba5898238 MD5 | raw file
Possible License(s): MIT
  1. require File.dirname(__FILE__) + '/helper'
  2. class TestConditionsTries < Test::Unit::TestCase
  3. # valid?
  4. def test_valid_should_return_false_if_times_not_set
  5. c = Conditions::Tries.new
  6. c.watch = stub(:name => 'foo')
  7. assert !c.valid?
  8. end
  9. end
  10. class TestConditionsTries < Test::Unit::TestCase
  11. def setup
  12. @c = Conditions::Tries.new
  13. @c.times = 3
  14. @c.prepare
  15. end
  16. # prepare
  17. def test_prepare_should_create_timeline
  18. assert_equal 3, @c.instance_variable_get(:@timeline).instance_variable_get(:@max_size)
  19. end
  20. # test
  21. def test_test_should_return_true_if_called_three_times_within_one_second
  22. assert !@c.test
  23. assert !@c.test
  24. assert @c.test
  25. end
  26. # reset
  27. def test_test_should_return_false_on_fourth_call_if_called_three_times_within_one_second
  28. 3.times { @c.test }
  29. @c.reset
  30. assert !@c.test
  31. end
  32. end
  33. class TestConditionsTriesWithin < Test::Unit::TestCase
  34. def setup
  35. @c = Conditions::Tries.new
  36. @c.times = 3
  37. @c.within = 1.seconds
  38. @c.prepare
  39. end
  40. # test
  41. def test_test_should_return_true_if_called_three_times_within_one_second
  42. assert !@c.test
  43. assert !@c.test
  44. assert @c.test
  45. end
  46. def test_test_should_return_false_if_called_three_times_within_two_seconds
  47. assert !@c.test
  48. assert !@c.test
  49. assert sleep(1.1)
  50. assert !@c.test
  51. end
  52. end