derailed-mole 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/History.txt +17 -0
  2. data/Manifest.txt +137 -0
  3. data/README.txt +216 -0
  4. data/Rakefile +46 -0
  5. data/bin/molify +64 -0
  6. data/config/database.yml +21 -0
  7. data/config/test_database.yml +69 -0
  8. data/lib/mole.rb +260 -0
  9. data/lib/mole/db/migrate.rb +90 -0
  10. data/lib/mole/e_mole.rb +75 -0
  11. data/lib/mole/e_mole_helper.rb +2 -0
  12. data/lib/mole/logger.rb +134 -0
  13. data/lib/mole/models/mole_feature.rb +58 -0
  14. data/lib/mole/models/mole_log.rb +31 -0
  15. data/lib/mole/module.rb +292 -0
  16. data/lib/mole/moler.rb +71 -0
  17. data/lib/mole/utils/frameworks.rb +53 -0
  18. data/lib/mole/version.rb +15 -0
  19. data/mole.gemspec +37 -0
  20. data/samples/merbapp/README +14 -0
  21. data/samples/merbapp/Rakefile +124 -0
  22. data/samples/merbapp/app/controllers/application.rb +3 -0
  23. data/samples/merbapp/app/controllers/exceptions.rb +13 -0
  24. data/samples/merbapp/app/controllers/moled.rb +25 -0
  25. data/samples/merbapp/app/helpers/global_helper.rb +5 -0
  26. data/samples/merbapp/app/mailers/views/layout/application.html.erb +1 -0
  27. data/samples/merbapp/app/mailers/views/layout/application.text.erb +1 -0
  28. data/samples/merbapp/app/parts/views/layout/application.html.erb +1 -0
  29. data/samples/merbapp/app/views/exceptions/internal_server_error.html.erb +216 -0
  30. data/samples/merbapp/app/views/exceptions/not_acceptable.html.erb +38 -0
  31. data/samples/merbapp/app/views/exceptions/not_found.html.erb +40 -0
  32. data/samples/merbapp/app/views/layout/application.html.erb +11 -0
  33. data/samples/merbapp/app/views/moled/index.html.erb +5 -0
  34. data/samples/merbapp/app/views/moled/result.html.erb +5 -0
  35. data/samples/merbapp/config/boot.rb +11 -0
  36. data/samples/merbapp/config/dependencies.rb +41 -0
  37. data/samples/merbapp/config/environments/development.rb +1 -0
  38. data/samples/merbapp/config/environments/production.rb +1 -0
  39. data/samples/merbapp/config/environments/test.rb +1 -0
  40. data/samples/merbapp/config/merb.yml +82 -0
  41. data/samples/merbapp/config/merb_init.rb +26 -0
  42. data/samples/merbapp/config/mole_config.rb +33 -0
  43. data/samples/merbapp/config/router.rb +38 -0
  44. data/samples/merbapp/config/upload.conf +0 -0
  45. data/samples/merbapp/public/images/merb.jpg +0 -0
  46. data/samples/merbapp/public/merb.fcgi +6 -0
  47. data/samples/merbapp/public/stylesheets/master.css +119 -0
  48. data/samples/merbapp/script/destroy +32 -0
  49. data/samples/merbapp/script/generate +32 -0
  50. data/samples/merbapp/script/stop_merb +13 -0
  51. data/samples/merbapp/spec/spec_helper.rb +15 -0
  52. data/samples/merbapp/test/test_helper.rb +14 -0
  53. data/samples/railsapp/README +14 -0
  54. data/samples/railsapp/Rakefile +10 -0
  55. data/samples/railsapp/app/controllers/application.rb +13 -0
  56. data/samples/railsapp/app/controllers/moled_controller.rb +24 -0
  57. data/samples/railsapp/app/helpers/application_helper.rb +3 -0
  58. data/samples/railsapp/app/views/moled/index.html.erb +5 -0
  59. data/samples/railsapp/app/views/moled/result.html.erb +5 -0
  60. data/samples/railsapp/config/boot.rb +109 -0
  61. data/samples/railsapp/config/database.yml +13 -0
  62. data/samples/railsapp/config/environment.rb +59 -0
  63. data/samples/railsapp/config/environments/development.rb +18 -0
  64. data/samples/railsapp/config/environments/production.rb +20 -0
  65. data/samples/railsapp/config/environments/test.rb +22 -0
  66. data/samples/railsapp/config/initializers/inflections.rb +10 -0
  67. data/samples/railsapp/config/initializers/mime_types.rb +5 -0
  68. data/samples/railsapp/config/initializers/mole.rb +10 -0
  69. data/samples/railsapp/config/moles/mole_config.rb +44 -0
  70. data/samples/railsapp/config/routes.rb +35 -0
  71. data/samples/railsapp/doc/README_FOR_APP +2 -0
  72. data/samples/railsapp/public/.htaccess +40 -0
  73. data/samples/railsapp/public/404.html +30 -0
  74. data/samples/railsapp/public/422.html +30 -0
  75. data/samples/railsapp/public/500.html +30 -0
  76. data/samples/railsapp/public/dispatch.cgi +10 -0
  77. data/samples/railsapp/public/dispatch.fcgi +24 -0
  78. data/samples/railsapp/public/dispatch.rb +10 -0
  79. data/samples/railsapp/public/favicon.ico +0 -0
  80. data/samples/railsapp/public/images/rails.png +0 -0
  81. data/samples/railsapp/public/javascripts/application.js +2 -0
  82. data/samples/railsapp/public/javascripts/controls.js +963 -0
  83. data/samples/railsapp/public/javascripts/dragdrop.js +972 -0
  84. data/samples/railsapp/public/javascripts/effects.js +1120 -0
  85. data/samples/railsapp/public/javascripts/prototype.js +4225 -0
  86. data/samples/railsapp/public/robots.txt +5 -0
  87. data/samples/railsapp/script/about +3 -0
  88. data/samples/railsapp/script/console +3 -0
  89. data/samples/railsapp/script/destroy +3 -0
  90. data/samples/railsapp/script/generate +3 -0
  91. data/samples/railsapp/script/performance/benchmarker +3 -0
  92. data/samples/railsapp/script/performance/profiler +3 -0
  93. data/samples/railsapp/script/performance/request +3 -0
  94. data/samples/railsapp/script/plugin +3 -0
  95. data/samples/railsapp/script/process/inspector +3 -0
  96. data/samples/railsapp/script/process/reaper +3 -0
  97. data/samples/railsapp/script/process/spawner +3 -0
  98. data/samples/railsapp/script/runner +3 -0
  99. data/samples/railsapp/script/server +3 -0
  100. data/samples/railsapp/test/test_helper.rb +38 -0
  101. data/samples/rubyapp/README +22 -0
  102. data/samples/rubyapp/bin/ruby_app +35 -0
  103. data/samples/rubyapp/config/mole_conf.rb +31 -0
  104. data/samples/rubyapp/lib/fred.rb +22 -0
  105. data/spec/config/auto_mole_config.rb +26 -0
  106. data/spec/config/mole_config.rb +0 -0
  107. data/spec/config/moles/fred_config.rb +0 -0
  108. data/spec/data/blee.rb +64 -0
  109. data/spec/db/migrate_spec.rb +19 -0
  110. data/spec/emole_spec.rb +43 -0
  111. data/spec/logger_spec.rb +56 -0
  112. data/spec/models/mole_feature_spec.rb +48 -0
  113. data/spec/models/mole_log_spec.rb +62 -0
  114. data/spec/module_spec.rb +229 -0
  115. data/spec/mole_spec.rb +135 -0
  116. data/spec/moler_spec.rb +77 -0
  117. data/spec/spec_helper.rb +76 -0
  118. data/spec/utils/framework_spec.rb +99 -0
  119. data/tasks/ann.rake +76 -0
  120. data/tasks/annotations.rake +22 -0
  121. data/tasks/doc.rake +48 -0
  122. data/tasks/gem.rake +110 -0
  123. data/tasks/manifest.rake +49 -0
  124. data/tasks/mole.rake +115 -0
  125. data/tasks/post_load.rake +26 -0
  126. data/tasks/rubyforge.rake +57 -0
  127. data/tasks/setup.rb +227 -0
  128. data/tasks/spec.rake +54 -0
  129. data/tasks/svn.rake +44 -0
  130. data/tasks/test.rake +38 -0
  131. data/templates/mole/e_mole/exception_alerts.rhtml +14 -0
  132. data/templates/mole/e_mole/feature_alerts.rhtml +11 -0
  133. data/templates/mole/e_mole/perf_alerts.rhtml +12 -0
  134. metadata +206 -0
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper" )
2
+
3
+ describe MoleFeature do
4
+ before( :each ) do
5
+ ::Mole.reset_configuration!
6
+ ::Mole.initialize( :application => "Test",
7
+ :mode => :persistent,
8
+ :log_level => :debug,
9
+ :moleable => true )
10
+ end
11
+
12
+ it "should find or create known features correctly" do
13
+ %w[ all performance exception].each do |f|
14
+ feature = MoleFeature.send( "find_#{f}_feature".to_sym, ::Mole.application )
15
+ feature.should_not be_nil
16
+ feature.name.downcase.should == f
17
+ end
18
+ end
19
+
20
+ it "should create a new feature" do
21
+ feature = MoleFeature.find_or_create_feature( "Fred", ::Mole.application, self.class.name )
22
+ feature.should_not be_nil
23
+ feature.name.should == "Fred"
24
+ feature.context.should == self.class.name
25
+ end
26
+
27
+ it "should not create a feature with no name" do
28
+ feature = MoleFeature.find_or_create_feature( "", ::Mole.application, self.class.name )
29
+ feature.should be_nil
30
+ end
31
+
32
+ it "should find all features for a given application correctly" do
33
+ %w[ all performance exception].each do |f|
34
+ MoleFeature.send( "find_#{f}_feature".to_sym, ::Mole.application )
35
+ end
36
+ MoleFeature.find_or_create_feature( "Fred", ::Mole.application, self.class.name )
37
+ features = MoleFeature.find_features( ::Mole.application )
38
+ features.should have(4).mole_features
39
+ end
40
+
41
+ it "should find moled application names correctly" do
42
+ MoleFeature.find_moled_application_names.should be_empty
43
+ %w[ all performance exception].each do |f|
44
+ feature = MoleFeature.send( "find_#{f}_feature".to_sym, ::Mole.application )
45
+ end
46
+ MoleFeature.find_moled_application_names.should == ["Test"]
47
+ end
48
+ end
@@ -0,0 +1,62 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper" )
2
+ require 'ostruct'
3
+
4
+ describe MoleLog do
5
+ before( :each ) do
6
+ ::Mole.reset_configuration!
7
+ ::Mole.initialize( :mode => :persistent, :log_level => :info, :moleable => true )
8
+ @args = { :blee => "Hello", :duh => "World" }
9
+ end
10
+
11
+ it "should log unchecked exceptions correctly" do
12
+ args = @args
13
+ feature = MoleFeature.find_exception_feature( ::Mole.application )
14
+ feature.should_not be_nil
15
+ begin
16
+ raise "Something crapped out"
17
+ rescue => boom
18
+ args[:boom] = Mole::Moler.dump_stack( boom )
19
+ MoleLog.log_it( self, feature, 100, args )
20
+ end
21
+ check_it( feature, 100, @args )
22
+ end
23
+
24
+ it "should log perf exception correctly" do
25
+ feature = MoleFeature.find_performance_feature( ::Mole.application )
26
+ feature.should_not be_nil
27
+ MoleLog.log_it( self, feature, 200, @args )
28
+ check_it( feature, 200, @args )
29
+ end
30
+
31
+ it "should mole a feature correctly" do
32
+ feature = MoleFeature.find_or_create_feature( "fred", ::Mole.application, "Test".class.name )
33
+ feature.should_not be_nil
34
+ MoleLog.log_it( "Test", feature, 300, @args )
35
+ check_it( feature, 300, @args )
36
+ end
37
+
38
+ it "should log request info correctly" do
39
+ ctrl = Moled::Controller.new
40
+ feature = MoleFeature.find_or_create_feature( "fred", ::Mole.application, ctrl.class.name )
41
+ feature.should_not be_nil
42
+ MoleLog.log_it( ctrl, feature, 400, @args )
43
+ log = check_it( feature, 400, @args )
44
+ log.ip_address.should == "1.1.1.1"
45
+ log.browser_type.should == "GodZilla"
46
+ end
47
+
48
+ # Test Controller...
49
+ module Moled
50
+ class Controller
51
+ class Request
52
+ def env
53
+ {'REMOTE_ADDR' => "1.1.1.1", 'HTTP_USER_AGENT' => 'GodZilla' }
54
+ end
55
+ end
56
+
57
+ def request
58
+ Request.new
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,229 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper" )
2
+
3
+
4
+ describe Module do
5
+ before( :all ) do
6
+ ::Mole.initialize( :perf_threshold => 1, :log_level => :info )
7
+ require File.join( File.dirname(__FILE__), %w[data blee] )
8
+ end
9
+
10
+ before( :each ) do
11
+ @blee = Blee.new
12
+ CallStackChecker.reset!
13
+ end
14
+
15
+ it "should handle features with punctuation correctly" do
16
+ Blee.mole_before( :feature => :get_out? ) { |context, feature, *args|
17
+ CallStackChecker.called
18
+ }
19
+ @blee.get_out?
20
+ CallStackChecker.should be_called
21
+ end
22
+
23
+ it "should trap mole before handler exceptions" do
24
+ Blee.mole_before( :feature => :crap_out ) { |context, feature, *args|
25
+ raise "LEGIT !! - Before - Something did crap out"
26
+ CallStackChecker.called
27
+ }
28
+ @blee.crap_out
29
+ CallStackChecker.should_not be_called
30
+ end
31
+
32
+ it "should trap mole after handler exceptions" do
33
+ Blee.mole_after( :feature => :crap_out ) { |context, feature, *args|
34
+ raise "LEGIT !! - After - Something did crap out"
35
+ CallStackChecker.called
36
+ }
37
+ @blee.crap_out
38
+ CallStackChecker.should_not be_called
39
+ end
40
+
41
+ it "should trap mole handler exceptions" do
42
+ Blee.mole_unchecked( :features => [:blee_raise_too] ) { |context, feature, *args|
43
+ raise "-- LEGIT !! - Unchecked - Something did crap out"
44
+ CallStackChecker.called
45
+ }
46
+ @blee.blee_raise_too rescue nil
47
+ CallStackChecker.should_not be_called
48
+ end
49
+
50
+ it "should trap a perf handler exception" do
51
+ Blee.mole_perf( :features => [:blee_slow_too] ) do |context, feature, elapsed_time, args, block|
52
+ raise "---LEGIT !! - Perf - Something did crap out"
53
+ CallStackChecker.called
54
+ end
55
+ @blee.blee_slow_too
56
+ CallStackChecker.should_not be_called
57
+ end
58
+
59
+ # it "should trap mole handler exceptions" do
60
+ # Blee.mole_before( :feature => :crap_out ) { |context, feature, *args|
61
+ # raise "Something did crap out"
62
+ # CallStackChecker.called
63
+ # }
64
+ # @blee.crap_out
65
+ # CallStackChecker.should_not be_called
66
+ # end
67
+
68
+ it "should correctly setup a before call" do
69
+ Blee.mole_before( :feature => :blee_no_args ) { |context, feature, block, *args|
70
+ context.class.should == Blee
71
+ feature.should == "blee_no_args"
72
+ block.should be_nil
73
+ args.should have(0).items
74
+ CallStackChecker.called
75
+ }
76
+ @blee.blee_no_args
77
+ CallStackChecker.should be_called
78
+ end
79
+
80
+ it "should correctly setup an after call" do
81
+ Blee.mole_after( :feature => :blee_no_args ) { |context, feature, ret_val, block, *args|
82
+ context.class.should == Blee
83
+ feature.should == "blee_no_args"
84
+ args.should have(0).items
85
+ CallStackChecker.called
86
+ }
87
+ @blee.blee_no_args
88
+ CallStackChecker.should be_called
89
+ end
90
+
91
+ it "should correctly trap an exception" do
92
+ Blee.mole_unchecked( :features => [:blee_raise] ) do |context, feature, boom, args, block|
93
+ context.class.should == Blee
94
+ feature.should == "blee_raise"
95
+ boom.to_s.should == "Blee exception"
96
+ CallStackChecker.called
97
+ end
98
+ @blee.blee_raise rescue nil
99
+ CallStackChecker.should be_called
100
+ end
101
+
102
+ it "should not trap a before call" do
103
+ @blee.blee_args( "Hello", "World", "Good", "Day" )
104
+ CallStackChecker.should_not be_called
105
+ end
106
+
107
+ it "should correctly trap the before call arguments" do
108
+ Blee.mole_before( :feature => :blee_args ) { |context, feature, block, *args|
109
+ context.class.should == Blee
110
+ feature.should == "blee_args"
111
+ args.should have(4).items
112
+ args[0].should == "Hello"
113
+ args[1].should == "World"
114
+ args[2].should == "Good"
115
+ args[3].should == "Day"
116
+ CallStackChecker.called
117
+ }
118
+ @blee.blee_args( "Hello", "World", "Good", "Day" )
119
+ CallStackChecker.should be_called
120
+ end
121
+
122
+ it "should correctly trap a before call with a block" do
123
+ Blee.mole_before( :feature => :blee_block ) do |context, feature, block, *args|
124
+ context.class.should == Blee
125
+ feature.should == "blee_block"
126
+ block.should_not be_nil
127
+ block.call.should == "Do it already!!"
128
+ args.size.should == 4
129
+ args[0].should == "Hello"
130
+ args[1].should == "World"
131
+ args[2].should == "Good"
132
+ args[3].should == "Day"
133
+ CallStackChecker.called
134
+ end
135
+ @blee.blee_block( "Hello", "World", "Good", "Day" ) { "Do it already!!" }
136
+ CallStackChecker.should be_called
137
+ end
138
+
139
+ it "should correctly trap the after call with many arguments" do
140
+ Blee.mole_after( :feature => :blee_args ) { |context, feature, ret_val, block, *args|
141
+ context.class.should == Blee
142
+ feature.should == "blee_args"
143
+ ret_val.should == 20
144
+ args.size.should == 4
145
+ args[0].should == "Hello"
146
+ args[1].should == "World"
147
+ args[2].should == "Good"
148
+ args[3].should == "Day"
149
+ CallStackChecker.called
150
+ }
151
+ @blee.blee_args( "Hello", "World", "Good", "Day" )
152
+ CallStackChecker.should be_called
153
+ end
154
+
155
+ it "should correctly trap the after call with a block" do
156
+ Blee.mole_after( :feature => :blee_block ) do |context, feature, ret_val, block, *args|
157
+ context.class.should == Blee
158
+ feature.should == "blee_block"
159
+ block.should_not be_nil
160
+ block.call.should == "Do it already!!"
161
+ ret_val.should == 10
162
+ args.size.should == 4
163
+ args[0].should == "Hello"
164
+ args[1].should == "World"
165
+ args[2].should == "Good"
166
+ args[3].should == "Day"
167
+ CallStackChecker.called
168
+ end
169
+ @blee.blee_block( "Hello", "World", "Good", "Day" ) { "Do it already!!" }
170
+ CallStackChecker.should be_called
171
+ end
172
+
173
+ it "should correctly trap a slow call" do
174
+ Blee.mole_perf( :features => [:blee_slow] ) do |context, feature, elapsed_time, ret_val, block, *args|
175
+ context.class.should == Blee
176
+ feature.should == "blee_slow"
177
+ ret_val.should == 1
178
+ block.should be_nil
179
+ args.size.should == 0
180
+ elapsed_time.should > 1
181
+ CallStackChecker.called
182
+ end
183
+ @blee.blee_slow
184
+ CallStackChecker.should be_called
185
+ end
186
+
187
+ it "should trap a private method correctly" do
188
+ Blee.mole_after( :feature => :blee_private ) { |context, feature, ret_val, block, *args|
189
+ context.class.should == Blee
190
+ feature.should == "blee_private"
191
+ ret_val.should == "Hello"
192
+ block.should be_nil
193
+ args.size.should == 1
194
+ args[0].should == "Hello"
195
+ CallStackChecker.called
196
+ }
197
+ @blee.send( :blee_private, "Hello" )
198
+ CallStackChecker.should be_called
199
+ end
200
+
201
+ it "should trap a protected method correctly" do
202
+ Blee.mole_after( :feature => :blee_protected ) { |context, feature, ret_val, block, *args|
203
+ context.class.should == Blee
204
+ feature.should == "blee_protected"
205
+ ret_val.should == "Hello"
206
+ block.should be_nil
207
+ args.size.should == 1
208
+ args[0].should == "Hello"
209
+ CallStackChecker.called
210
+ }
211
+ @blee.send( :blee_protected, "Hello" )
212
+ CallStackChecker.should be_called
213
+ end
214
+
215
+ it "should mole a static method correctly" do
216
+ pending do
217
+ Blee.mole_after( :feature => :blee_static ) { |context, feature, ret_val, block, *args|
218
+ context.class.should == Blee
219
+ feature.should == "blee_static"
220
+ ret_val.should be_nil
221
+ block.should be_nil
222
+ args.size.should == 0
223
+ CallStackChecker.called
224
+ }
225
+ Blee.blee_static
226
+ CallStackChecker.should be_called
227
+ end
228
+ end
229
+ end
data/spec/mole_spec.rb ADDED
@@ -0,0 +1,135 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper" )
2
+
3
+ describe Mole do
4
+ before( :all ) do
5
+ ::Mole.reset_configuration!
6
+ ::Mole.initialize( :moleable => true )
7
+ @root = ::File.expand_path( ::File.join(::File.dirname(__FILE__), ".." ) )
8
+ end
9
+
10
+ it "is versioned" do
11
+ ::Mole::Version.version.should =~ /\d+\.\d+\.\d+/
12
+ end
13
+
14
+ it "should have the right defaults" do
15
+ Mole.should be_moleable
16
+ Mole.logger.should_not be_nil
17
+ Mole.perf_threshold.should == 5
18
+ Mole.should_not be_persistent
19
+ Mole.application.should == "Default"
20
+ end
21
+
22
+ it "generates a correct path relative to root" do
23
+ Mole.path( "mole.rb" ).should == ::File.join(@root, "mole.rb" )
24
+ end
25
+
26
+ it "generates a correct path relative to lib" do
27
+ Mole.libpath(%w[ mole db_mole.rb]).should == ::File.join(@root, "lib", "mole", "db_mole.rb")
28
+ end
29
+
30
+ it "should define the correct run modes" do
31
+ Mole.run_modes.should == [:transient,:persistent]
32
+ end
33
+
34
+ it "should dump config info to console" do
35
+ Mole.dump
36
+ end
37
+
38
+ it "should locate controller classes correctly" do
39
+ classes = Mole.find_controller_classes( File.join(File.dirname(__FILE__), %w[data] ) )
40
+ classes.should == %w[Blee]
41
+ end
42
+
43
+ describe ".auto_xxx" do
44
+ before( :each ) do
45
+ ::Mole.reset_configuration!
46
+ ::Mole.initialize( :perf_threshold => 1, :log_level => :debug )
47
+ require File.join( File.dirname(__FILE__), %w[data blee] )
48
+ Blee.send( :mole_clear! )
49
+ CallStackChecker.reset!
50
+ end
51
+
52
+ it "should auto perf a set of controllers correctly" do
53
+ Mole.auto_perf( File.join(File.dirname(__FILE__), %w[data] ) ) do |context, feature, elapsed_time, ret_val, block, *args|
54
+ context.class.should == Blee
55
+ block.should be_nil
56
+ args.size.should == 0
57
+ elapsed_time.should > 1
58
+ CallStackChecker.called
59
+ end
60
+ Blee.new.blee_slow
61
+ CallStackChecker.should be_called
62
+ CallStackChecker.reset!
63
+ Blee.new.blee_slow_too
64
+ CallStackChecker.should be_called
65
+ end
66
+
67
+ it "should auto check a set of controllers correctly" do
68
+ Mole.auto_unchecked( File.join(File.dirname(__FILE__), %w[data] ) ) do |context, feature, elapsed_time, block, *args|
69
+ context.class.should == Blee
70
+ feature.should == "blee_raise"
71
+ block.should be_nil
72
+ args.size.should == 0
73
+ CallStackChecker.called
74
+ end
75
+ Blee.new.blee_raise rescue nil
76
+ CallStackChecker.should be_called
77
+ end
78
+
79
+ it "should auto before a set of controllers correctly" do
80
+ Mole.auto_before( File.join(File.dirname(__FILE__), %w[data] ) ) do |context, feature, block, *args|
81
+ context.class.should == Blee
82
+ feature.should == "blee_no_args"
83
+ block.should be_nil
84
+ args.size.should == 0
85
+ CallStackChecker.called
86
+ end
87
+ Blee.new.blee_no_args
88
+ CallStackChecker.should be_called
89
+ end
90
+
91
+ it "should auto after a set of controllers correctly" do
92
+ Mole.auto_after( File.join(File.dirname(__FILE__), %w[data] ) ) do |context, feature, ret_val, block, *args|
93
+ context.class.should == Blee
94
+ feature.should == "blee_no_args"
95
+ ret_val.should == 10
96
+ block.should be_nil
97
+ args.size.should == 0
98
+ CallStackChecker.called
99
+ end
100
+ Blee.mole_dump( "After" )
101
+ Blee.new.blee_no_args
102
+ CallStackChecker.should be_called
103
+ end
104
+
105
+ end
106
+
107
+ describe ".load_mole_configuration" do
108
+ before( :each ) do
109
+ ::Mole.reset_configuration!
110
+ end
111
+
112
+ it "should load single file correctly" do
113
+ ::Mole.initialize( :moleable => true, :mole_config => File.join( File.dirname(__FILE__), %w[config mole_config.rb] ) )
114
+ ::Mole.load_mole_configuration
115
+ require( File.join( File.dirname(__FILE__), %w[config mole_config.rb] ) ).should == []
116
+ end
117
+
118
+ it "should load config for directory correctly" do
119
+ ::Mole.initialize( :moleable => true, :mole_config => File.join( File.dirname(__FILE__), %w[config moles] ) )
120
+ ::Mole.load_mole_configuration
121
+ require( File.join( File.dirname(__FILE__), %w[config moles fred_config.rb] ) ).should == []
122
+ end
123
+
124
+ it "should raise an error if the configuration file does not exist" do
125
+ ::Mole.initialize( :moleable => true, :mole_config => File.join( File.dirname(__FILE__), %w[config fred_mole.rb] ) )
126
+ lambda{ ::Mole.load_mole_configuration }.should raise_error( "Unable to find the MOle configuration from `./spec/config/fred_mole.rb" )
127
+ end
128
+
129
+ it "should raise an error if the config directory does not exist" do
130
+ ::Mole.initialize( :moleable => true, :mole_config => File.join( File.dirname(__FILE__), %w[config freds] ) )
131
+ lambda{ ::Mole.load_mole_configuration }.should raise_error( "Unable to find the MOle configuration from `./spec/config/freds" )
132
+ end
133
+ end
134
+
135
+ end