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