Reporter and Server DRb-ready classes
[god.git] / test / helper.rb
blob0938c8760b42b36d2db16f0d1ea5e4eac98a37ed
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     puts "=> You need the Mocha gem to run these tests."
14     exit
15   end
16 end
18 include God
20 module God
21   class ExitCalledError < StandardError
22   end
24   class Base
25     def exit
26       raise ExitCalledError.new("exit called")
27     end
28   end
30   class FakeCondition < Condition
31     def test
32       true
33     end
34   end
35   
36   module Behaviors
37     class FakeBehavior < Behavior
38     end
39   end
40 end
42 # This allows you to be a good OOP citizen and honor encapsulation, but
43 # still make calls to private methods (for testing) by doing
45 #   obj.bypass.private_thingie(arg1, arg2)
47 # Which is easier on the eye than
49 #   obj.send(:private_thingie, arg1, arg2)
51 class Object
52   class Bypass
53     instance_methods.each do |m|
54       undef_method m unless m =~ /^__/
55     end
57     def initialize(ref)
58       @ref = ref
59     end
60   
61     def method_missing(sym, *args)
62       @ref.__send__(sym, *args)
63     end
64   end
66   def bypass
67     Bypass.new(self)
68   end
69 end