extracted behavior code
[god.git] / test / helper.rb
blob40566c6536989ed276ce65129b461c0e0824c211
1 require File.join(File.dirname(__FILE__), *%w[.. lib god])
3 require 'test/unit'
4 # require 'mocha'
6 include God
8 module God
9   class ExitCalledError < StandardError
10   end
12   class Base
13     def exit
14       raise ExitCalledError.new("exit called")
15     end
16   end
18   class FakeCondition < Condition
19     def test
20       true
21     end
22   end
23   
24   module Behaviors
25     class FakeBehavior < Behavior
26     end
27   end
28 end
30 # This allows you to be a good OOP citizen and honor encapsulation, but
31 # still make calls to private methods (for testing) by doing
33 #   obj.bypass.private_thingie(arg1, arg2)
35 # Which is easier on the eye than
37 #   obj.send(:private_thingie, arg1, arg2)
39 class Object
40   class Bypass
41     instance_methods.each do |m|
42       undef_method m unless m =~ /^__/
43     end
45     def initialize(ref)
46       @ref = ref
47     end
48   
49     def method_missing(sym, *args)
50       @ref.__send__(sym, *args)
51     end
52   end
54   def bypass
55     Bypass.new(self)
56   end
57 end