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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
require 'rubygems'
require File.join(File.dirname(__FILE__), *%w[.. lib god sys_logger])
require File.join(File.dirname(__FILE__), *%w[.. lib god])
God::EventHandler.load
require 'test/unit'
require 'set'
include God
if Process.uid != 0 and RbConfig::CONFIG['host_os'] == "linux"
abort <<-EOF
\n
*********************************************************************
* *
* You need to run these tests as root *
* chroot and netlink (linux only) require it *
* *
*********************************************************************
EOF
end
begin
require 'mocha'
rescue LoadError
unless gems ||= false
require 'rubygems'
gems = true
retry
else
abort "=> You need the Mocha gem to run these tests."
end
end
module God
module Conditions
class FakeCondition < Condition
def test
true
end
end
class FakePollCondition < PollCondition
def test
true
end
end
class FakeEventCondition < EventCondition
def register
end
def deregister
end
end
end
module Behaviors
class FakeBehavior < Behavior
def before_start
'foo'
end
def after_start
'bar'
end
end
end
module Contacts
class FakeContact < Contact
end
class InvalidContact
end
end
def self.reset
self.watches = nil
self.groups = nil
self.server = nil
self.inited = nil
self.host = nil
self.port = nil
self.pid_file_directory = nil
self.registry.reset
end
end
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, nil
yield
ensure
$VERBOSE = old_verbose
end
LOG.instance_variable_set(:@io, StringIO.new('/dev/null'))
module Kernel
def abort(text)
raise SystemExit
end
def exit(code)
raise SystemExit
end
end
module Test::Unit::Assertions
def assert_abort
assert_raise SystemExit do
yield
end
end
end
# This allows you to be a good OOP citizen and honor encapsulation, but
# still make calls to private methods (for testing) by doing
#
# obj.bypass.private_thingie(arg1, arg2)
#
# Which is easier on the eye than
#
# obj.send(:private_thingie, arg1, arg2)
#
class Object
class Bypass
instance_methods.each do |m|
undef_method m unless m =~ /^(__|object_id)/
end
def initialize(ref)
@ref = ref
end
def method_missing(sym, *args)
@ref.__send__(sym, *args)
end
end
def bypass
Bypass.new(self)
end
end
|