File: test_condition.rb

package info (click to toggle)
ruby-god 0.12.1-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 752 kB
  • sloc: ruby: 5,913; ansic: 217; makefile: 3
file content (50 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require File.dirname(__FILE__) + '/helper'

class BadlyImplementedCondition < PollCondition
end

class TestCondition < Test::Unit::TestCase

  # generate

  def test_generate_should_return_an_object_corresponding_to_the_given_type
    assert_equal Conditions::ProcessRunning, Condition.generate(:process_running, nil).class
  end

  def test_generate_should_raise_on_invalid_type
    assert_raise NoSuchConditionError do
      Condition.generate(:foo, nil)
    end
  end

  def test_generate_should_abort_on_event_condition_without_loaded_event_system
    God::EventHandler.stubs(:operational?).returns(false)
    assert_abort do
      God::EventHandler.start
      Condition.generate(:process_exits, nil).class
    end
  end

  def test_generate_should_return_a_good_error_message_for_invalid_types
    emsg = "No Condition found with the class name God::Conditions::FooBar"
    rmsg = nil

    begin
      Condition.generate(:foo_bar, nil)
    rescue => e
      rmsg = e.message
    end

    assert_equal emsg, rmsg
  end

  # test

  def test_test_should_raise_if_not_defined_in_subclass
    c = BadlyImplementedCondition.new

    assert_raise AbstractMethodNotOverriddenError do
      c.test
    end
  end
end