moved to timer based poll mechanism
[god.git] / test / helper.rb
blobb983859dc17acbb0d02d05b706341112eb5681c1
1 require File.join(File.dirname(__FILE__), *%w[.. lib god])
3 require 'test/unit'
5 begin
6   require 'mocha'
7 rescue LoadError
8   unless gems ||= false
9     require 'rubygems'
10     gems = true
11     retry
12   else
13     abort "=> You need the Mocha gem to run these tests."
14   end
15 end
17 include God
19 module God
20   class AbortCalledError < StandardError
21   end
23   class Base
24     def abort(msg)
25       raise AbortCalledError.new("abort called")
26     end
27     
28     def self.abort(msg)
29       raise AbortCalledError.new("abort called")
30     end
31   end
33   module Conditions
34     class FakeCondition < Condition
35       def test
36         true
37       end
38     end
39   
40     class FakePollCondition < PollCondition
41       def test
42         true
43       end
44     end
45   
46     class FakeEventCondition < EventCondition
47       def test
48         true
49       end
50     end
51   end
52   
53   module Behaviors
54     class FakeBehavior < Behavior
55     end
56   end
57 end
59 def silence_warnings
60   old_verbose, $VERBOSE = $VERBOSE, nil
61   yield
62 ensure
63   $VERBOSE = old_verbose
64 end
66 # This allows you to be a good OOP citizen and honor encapsulation, but
67 # still make calls to private methods (for testing) by doing
69 #   obj.bypass.private_thingie(arg1, arg2)
71 # Which is easier on the eye than
73 #   obj.send(:private_thingie, arg1, arg2)
75 class Object
76   class Bypass
77     instance_methods.each do |m|
78       undef_method m unless m =~ /^__/
79     end
81     def initialize(ref)
82       @ref = ref
83     end
84   
85     def method_missing(sym, *args)
86       @ref.__send__(sym, *args)
87     end
88   end
90   def bypass
91     Bypass.new(self)
92   end
93 end