duck_test 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/bin/ducktest +29 -0
  2. data/lib/duck_test/autoload_config.rb +103 -0
  3. data/lib/duck_test/base.rb +41 -0
  4. data/lib/duck_test/commands.rb +208 -0
  5. data/lib/duck_test/config.rb +675 -0
  6. data/lib/duck_test/config_helper.rb +99 -0
  7. data/lib/duck_test/console.rb +18 -0
  8. data/lib/duck_test/default_config.rb +48 -0
  9. data/lib/duck_test/frame_work/base.rb +587 -0
  10. data/lib/duck_test/frame_work/file_manager.rb +511 -0
  11. data/lib/duck_test/frame_work/filter_set.rb +233 -0
  12. data/lib/duck_test/frame_work/map.rb +331 -0
  13. data/lib/duck_test/frame_work/queue.rb +221 -0
  14. data/lib/duck_test/frame_work/queue_event.rb +29 -0
  15. data/lib/duck_test/frame_work/rspec/base.rb +17 -0
  16. data/lib/duck_test/frame_work/rspec/frame_work.rb +30 -0
  17. data/lib/duck_test/frame_work/test_unit/base.rb +14 -0
  18. data/lib/duck_test/frame_work/test_unit/frame_work.rb +33 -0
  19. data/lib/duck_test/frame_work/watch_config.rb +69 -0
  20. data/lib/duck_test/gem/helper.rb +107 -0
  21. data/lib/duck_test/logger.rb +127 -0
  22. data/lib/duck_test/option_parser.rb +30 -0
  23. data/lib/duck_test/platforms/base.rb +18 -0
  24. data/lib/duck_test/platforms/dependencies.rb +18 -0
  25. data/lib/duck_test/platforms/generic/base.rb +15 -0
  26. data/lib/duck_test/platforms/generic/listener.rb +104 -0
  27. data/lib/duck_test/platforms/linux/base.rb +15 -0
  28. data/lib/duck_test/platforms/linux/listener.rb +76 -0
  29. data/lib/duck_test/platforms/listener.rb +303 -0
  30. data/lib/duck_test/platforms/mac/base.rb +15 -0
  31. data/lib/duck_test/platforms/mac/listener.rb +79 -0
  32. data/lib/duck_test/platforms/mac/listener.rb.orig +147 -0
  33. data/lib/duck_test/platforms/os_helper.rb +102 -0
  34. data/lib/duck_test/platforms/watch_event.rb +47 -0
  35. data/lib/duck_test/platforms/windows/base.rb +15 -0
  36. data/lib/duck_test/platforms/windows/listener.rb +123 -0
  37. data/lib/duck_test/railtie.rb +29 -0
  38. data/lib/duck_test/usage.rb +34 -0
  39. data/lib/duck_test/usage.yml +112 -0
  40. data/lib/duck_test/version.rb +3 -0
  41. data/lib/duck_test.rb +6 -0
  42. data/lib/notes.txt +215 -0
  43. data/lib/tasks/duck_tests.rake +35 -0
  44. data/lib/tasks/gem_tasks.rake +18 -0
  45. metadata +92 -0
@@ -0,0 +1,675 @@
1
+ module DuckTest
2
+
3
+ # Data and methods to define and configure runnable watch lists, frameworks, everything to control the behavior of DuckTest.
4
+ class Config
5
+ include LoggerHelper
6
+
7
+ ##################################################################################
8
+ def initialize
9
+
10
+ super
11
+
12
+ Logger.log_level = :debug
13
+
14
+ #self.class.reset
15
+
16
+ if defined?(Rails)
17
+ root Rails.root
18
+ end
19
+
20
+ end
21
+
22
+ ##################################################################################
23
+ # This is a boolean flag used to determine if at least one config block has been run during start up.
24
+ # If a block has not been run, then, DuckTest will attempt to autoload a default configuration for the current target testing
25
+ # framework.
26
+ # @return [TrueClass, FalseClass] A boolean indicating if at least one config block has been run.
27
+ def self.block_run
28
+ @@block_run = false unless defined?(@@block_run)
29
+ return @@block_run
30
+ end
31
+
32
+ def self.block_run?
33
+ return self.block_run
34
+ end
35
+
36
+ def self.block_run=(value)
37
+ @@block_run = value
38
+ end
39
+
40
+ ##################################################################################
41
+ # Returns the current configuration Hash containing attributes for paths, testing frameworks, etc.
42
+ # @return [Hash]
43
+ def self.config
44
+ reset unless defined?(@@config)
45
+ return @@config
46
+ end
47
+
48
+ ##################################################################################
49
+ # Sets default values for all configuration attributes and adds a default testing framework.
50
+ # @return [Hash] The current configuration Hash.
51
+ def self.reset
52
+ @@config = {default_framework: :testunit}
53
+
54
+ # defaults for a testing framework are set by get_framework if it does not already exist
55
+ # make a call to set the defaults
56
+ self.get_framework(:testunit)
57
+
58
+ return @@config
59
+ end
60
+
61
+ ##################################################################################
62
+ # Sets and returns the value of {.default_framework}.
63
+ #
64
+ # DuckTest.config do
65
+ #
66
+ # # will load :rspec framework by default
67
+ # default_framework :rspec
68
+ #
69
+ # end
70
+ #
71
+ # @return [Symbol] Current value of {.default_framework}
72
+ def default_framework(value = nil)
73
+ self.class.default_framework = value
74
+ return self.class.default_framework
75
+ end
76
+
77
+ ##################################################################################
78
+ # Gets the current value of :default_framework
79
+ # @return [Symbol] Current value of :default_framework
80
+ def self.default_framework
81
+ return self.config[:default_framework]
82
+ end
83
+
84
+ ##################################################################################
85
+ # Sets the default testing framework to load when the Rails console starts.
86
+ # @return [Symbol] Current value of :default_framework
87
+ def self.default_framework=(value)
88
+ self.config[:default_framework] = value.to_sym unless value.blank?
89
+ return self.config[:default_framework]
90
+ end
91
+
92
+ ##################################################################################
93
+ # Returns the instance of the testing framework that is currently loaded.
94
+ # @return [DuckTest::FrameWork::Base]
95
+ def self.framework
96
+ @@framework = nil unless defined?(@@framework)
97
+ return @@framework
98
+ end
99
+
100
+ ##################################################################################
101
+ # Conveinence method to return the name of the current testing framework. This is used
102
+ # throughout the code base in debugging statements.
103
+ # @return [String]
104
+ def self.framework_name
105
+ return self.framework.blank? ? "not set yet" : self.framework.name
106
+ end
107
+
108
+ ##################################################################################
109
+ # Reloads the current target framework.
110
+ # @return [NilClass]
111
+ def self.reload!
112
+ if defined?(@@framework) && !@@framework.blank?
113
+ # this should be changed to debug later
114
+ ducklog.console "framework already loaded. shutting it down... #{@@framework.blank?}"
115
+ remove_class_variable(:@@framework)
116
+ end
117
+
118
+ unless ENV["DUCK_TEST"].blank?
119
+ self.default_framework = ENV["DUCK_TEST"]
120
+ end
121
+
122
+ target = self.default_framework
123
+
124
+ DuckTest::DefaultConfig.config(target) unless self.block_run?
125
+
126
+ case target
127
+ when :testunit
128
+ @@framework = DuckTest::FrameWork::TestUnit::FrameWork.new(target).startup(self.get_framework(target))
129
+
130
+ when :rspec
131
+ @@framework = DuckTest::FrameWork::RSpec::FrameWork.new(target).startup(self.get_framework(target))
132
+
133
+ end
134
+
135
+ return nil
136
+ end
137
+
138
+ ##################################################################################
139
+ # Sets the root directory for all test/spec files to watch. Typically, this will equate to Rails.root
140
+ #
141
+ # # sets the root directory
142
+ # DuckTest.config do
143
+ # root "/my_root"
144
+ # end
145
+ #
146
+ # puts DuckTest::Config.root # => "/my_root"
147
+ #
148
+ # @return [NilClass]
149
+ def root(value)
150
+ self.get_framework(self.current_framework)[:root] = value.to_s unless value.blank?
151
+ return nil
152
+ end
153
+
154
+ ##################################################################################
155
+ # Sets if tests/specs should be run automatically when changed.
156
+ #
157
+ # # shuts autorun off
158
+ # DuckTest.config do
159
+ # autorun false
160
+ # end
161
+ # @param [Boolean] value (Default: true) A value of true means test will be automatically run, otherwise, tests have to be run manually.
162
+ # @return [NilClass]
163
+ def autorun(value)
164
+ self.get_framework(self.current_framework)[:autorun] = value
165
+ return nil
166
+ end
167
+
168
+ ##################################################################################
169
+ # @note See {Config#watch_basedir Config#watch_basedir} for an explanation of base directories.
170
+ # Sets the base directory for all runnable test files.
171
+ # @param [String, Symbol] value A valid directory path.
172
+ # @return [NilClass]
173
+ def runnable_basedir(value)
174
+ unless value.blank?
175
+ self.get_framework(self.current_framework)[:runnable_basedir] = value.to_s
176
+ end
177
+ return nil
178
+ end
179
+
180
+ ##################################################################################
181
+ # Sets the base directory for all non-runnable (watched) files. Base directories are provided as a conveinence
182
+ # to help keep configuration files from becoming cluttered. Basically, removes the need to include directory
183
+ # names when defining runnable and watch configurations.
184
+ #
185
+ # # without base directories
186
+ # DuckTest.config do
187
+ # watch "app/**/*" do
188
+ # map sub_directory: /^app/models/, file_name: /[a-z]/ do
189
+ # map sub_directory: /^test\/unit/, file_name: /[a-z]/
190
+ # map sub_directory: /^test\/functional/, file_name: /[a-z]/
191
+ # end
192
+ # end
193
+ # end
194
+ #
195
+ # # with base directories
196
+ # DuckTest.config do
197
+ #
198
+ # runnable_basedir :test
199
+ # watch_basedir :app
200
+ #
201
+ # watch "**/*" do
202
+ # map sub_directory: /^models/, file_name: /[a-z]/ do
203
+ # map sub_directory: /^unit/, file_name: /[a-z]/
204
+ # map sub_directory: /^functional/, file_name: /[a-z]/
205
+ # end
206
+ # end
207
+ # end
208
+ #
209
+ # @param [String, Symbol] value A valid directory path.
210
+ # @return [NilClass]
211
+ def watch_basedir(value)
212
+ unless value.blank?
213
+ self.get_framework(self.current_framework)[:watch_basedir] = value.to_s
214
+ end
215
+ return nil
216
+ end
217
+
218
+ ##################################################################################
219
+ # Sets the excluded filter.
220
+ # @param [Regexp] value A valid Regexp as per {FrameWork::FilterSet#excluded}
221
+ # @return [NilClass]
222
+ def excluded(value = nil)
223
+ if self.current_watch_config
224
+ self.current_watch_config.filter_set.excluded = value
225
+ else
226
+ self.get_framework(self.current_framework)[:excluded] = value
227
+ end
228
+ return nil
229
+ end
230
+
231
+ ##################################################################################
232
+ # Sets the excluded_dirs filter.
233
+ # @param [Regexp] value A valid Regexp as per {FrameWork::FilterSet#excluded_dirs}
234
+ # @return [NilClass]
235
+ def excluded_dirs(value = nil)
236
+ if self.current_watch_config
237
+ self.current_watch_config.filter_set.excluded_dirs = value
238
+ else
239
+ self.get_framework(self.current_framework)[:excluded_dirs] = value
240
+ end
241
+ return nil
242
+ end
243
+
244
+ ##################################################################################
245
+ # Sets the included filter.
246
+ # @param [Regexp] value A valid Regexp as per {FrameWork::FilterSet#included}
247
+ # @return [NilClass]
248
+ def included(value = nil)
249
+ if self.current_watch_config
250
+ self.current_watch_config.filter_set.included = value
251
+ else
252
+ self.get_framework(self.current_framework)[:included] = value
253
+ end
254
+ return nil
255
+ end
256
+
257
+ ##################################################################################
258
+ # Sets the included_dirs filter.
259
+ # @param [Regexp] value A valid Regexp as per {FrameWork::FilterSet#included_dirs}
260
+ # @return [NilClass]
261
+ def included_dirs(value = nil)
262
+ if self.current_watch_config
263
+ self.current_watch_config.filter_set.included_dirs = value
264
+ else
265
+ self.get_framework(self.current_framework)[:included_dirs] = value
266
+ end
267
+ return nil
268
+ end
269
+
270
+ ##################################################################################
271
+ # Sets the non_loadable filter.
272
+ # @param [Regexp] value A valid Regexp as per {FrameWork::FilterSet#non_loadable}
273
+ # @return [NilClass]
274
+ def non_loadable(value = nil)
275
+ if self.current_watch_config
276
+ self.current_watch_config.filter_set.non_loadable = value
277
+ else
278
+ self.get_framework(self.current_framework)[:non_loadable] = value
279
+ end
280
+ return nil
281
+ end
282
+
283
+ ##################################################################################
284
+ # Represents the current framework being configured.
285
+ #
286
+ # DuckTest.config do
287
+ # puts current_framework # => :testunit
288
+ # end
289
+ #
290
+ def current_framework
291
+ @current_framework ||= self.default_framework
292
+ return @current_framework
293
+ end
294
+
295
+ ##################################################################################
296
+ # Sets the current framework to configure. Value can be a String or Symbol, however, the value
297
+ # will be converted to a Symbol when assigned. Examples of valid values are: :testunit, :rpsec, :minitest
298
+ #
299
+ # # sets the current framework to :rspec
300
+ # DuckTest.config do
301
+ # current_framework = :rspec
302
+ # end
303
+ #
304
+ # @return [Symbol]
305
+ ##################################################################################
306
+ def current_framework=(value)
307
+ @current_framework ||= self.current_framework
308
+ @current_framework = value.to_sym
309
+ return @current_framework
310
+ end
311
+
312
+ ##################################################################################
313
+ # ...
314
+ def current_watch_config
315
+ return @current_watch_config
316
+ end
317
+
318
+ ##################################################################################
319
+ # ...
320
+ def current_watch_config=(value)
321
+ @current_watch_config = value
322
+ return @current_watch_config
323
+ end
324
+
325
+ ##################################################################################
326
+ # Returns a Hash representing the configuration for a framework.
327
+ #
328
+ # @return [Hash]
329
+ def self.get_framework(key)
330
+ self.config[key] = {root: ".", autorun: true, runnable_basedir: "test", watch_basedir: "app"} unless self.config[key].kind_of?(Hash)
331
+ return self.config[key]
332
+ end
333
+
334
+ # ...
335
+ def get_framework(key)
336
+ unless self.class.config[key]
337
+ test_unit_framework = self.class.config[:testunit]
338
+ if test_unit_framework
339
+ self.class.get_framework(key)[:autorun] = test_unit_framework[:autorun]
340
+ self.class.get_framework(key)[:runnable_basedir] = test_unit_framework[:runnable_basedir]
341
+ self.class.get_framework(key)[:watch_basedir] = test_unit_framework[:watch_basedir]
342
+ self.class.get_framework(key)[:excluded] = test_unit_framework[:excluded]
343
+ self.class.get_framework(key)[:excluded_dirs] = test_unit_framework[:excluded_dirs]
344
+ self.class.get_framework(key)[:included] = test_unit_framework[:included]
345
+ self.class.get_framework(key)[:included_dirs] = test_unit_framework[:included_dirs]
346
+ end
347
+ end
348
+ return self.class.get_framework(key)
349
+ end
350
+
351
+ ##################################################################################
352
+ # Configures a framework
353
+ # @param [String, Symbol] key Key is the name of the framework to configure. Key is converted to a Symbol regardless of what value is passed.
354
+ # @param [Hash] options Options hash. No options implemented at this time. However, the Hash is passed to the block when executed.
355
+ # @return [NilClass]
356
+ def framework(key, options = {}, &block)
357
+ prev_value = self.current_framework
358
+
359
+ self.current_framework = key
360
+
361
+ config = {framework: self.current_framework}.merge(options)
362
+
363
+ yield config if block_given?
364
+
365
+ self.current_framework = prev_value
366
+
367
+ return nil
368
+ end
369
+
370
+ ##################################################################################
371
+ # Watches a set of directories / files based on a pattern. You can include an options Hash containing combinations of Regexps, Strings, and Symbols
372
+ # to filter which directories files are actually watched. There are basically two types of file sets that are watched.
373
+ # - <b>runnable</b> test files (Test::Unit, RSpec, etc.) are defined using {#runnable}, which is simply a wrapper for the {#watch} method.
374
+ # The intent is that you can define a set of runnable tests that will be automagically executed when they are changed and saved.
375
+ # - <b>non-runnable</b> files are anything except a runnable file. Typically, all of the files under the app directory of a Rails application.
376
+ # The intent is that you can define non-runnable that are watched and mapped to runnable files that are triggered when non-runnable files are changed and saved.
377
+ #
378
+ # Example
379
+ # # I'm showing how to set the default base directories for runnable and non-runnable files for clarity.
380
+ # # The default settings of :test and :app are set for you during initialization.
381
+ # DuckTest.config do
382
+ # runnable_basedir: :test
383
+ # watch_basedir: :app
384
+ #
385
+ # runnable "**/*", # watches all of the runnable files in the test directory of a Rails app.
386
+ # watch "**/*" # watches all of the non-runnable application files in the app directory of a Rails app.
387
+ # end
388
+ #
389
+ # # Same as above, however, includes a filter
390
+ # DuckTest.config do
391
+ # watch "**/*", [/^bike/, /^car/, /^truck/]
392
+ # end
393
+ #
394
+ # A good way to think of the {#runnable} and {#watch} methods is we are using the standard Dir.glob method to retrieve a file set from disk and
395
+ # using Regexp, String, Symbols, and Arrays or any combinations of the three to filter the file set via includes and excludes. This should
396
+ # be more enough to satisfy any need.
397
+ #
398
+ # In an attempt to help configuration from looking cluttered, the watch method will attempt to be smart about grabbing arguments.
399
+ # You can specify included filters outside of the options Hash. Meaning, you do not have to specify included:
400
+ #
401
+ # # both of the following are equivalent
402
+ # DuckTest.config do
403
+ # watch "**/*", /^books/ # assumes the second argument is the included: filter
404
+ # watch "**/*", [/^books/, /^truck/]
405
+ #
406
+ # watch "**/*", included: /^books/ # explicitly defines the included: filter
407
+ # watch "**/*", included: [/^books/, /^truck/]
408
+ # end
409
+ #
410
+ # # all of the following are equivalent
411
+ # watch "**/*", /^trucks/
412
+ # watch "**/*", [/^trucks/]
413
+ # watch "**/*", included: /^trucks/
414
+ # watch "**/*", included: [/^trucks/]
415
+ # watch "**/*",[/^trucks/, /^cars/]
416
+ # watch "**/*", included: [/^trucks/, /^cars/]
417
+ #
418
+ # # all of the following are equivalent
419
+ # watch "**/*", :all
420
+ # watch "**/*", included: :all
421
+ # watch "**/*", included: [:all]
422
+ #
423
+ # The included and excluded filters follow all of the same rules as {FrameWork::FileManager#watchable?}. It is possible to do some moderately complex filtering such as:
424
+ #
425
+ # watch "**/*", included: /bike/, excluded: /truck/, included_dirs: [/models/, /controllers/], excluded_dirs: /views/
426
+ #
427
+ # Since pattern is compliant with {http://ruby-doc.org/core-1.9.3/Dir.html#method-c-glob} the following are valid.
428
+ #
429
+ # watch "models**/*"
430
+ #
431
+ # watch ["models**/*", "controllers**/*"]
432
+ #
433
+ # @overload watch(pattern, included, options = {}, &block)
434
+ # @param [String] pattern Pattern is compliant with {http://ruby-doc.org/core-1.9.3/Dir.html#method-c-glob}
435
+ # @param [String] included
436
+ # @param [Hash] options Options hash for watch list configurations.
437
+ # - :included See {FrameWork::FilterSet#included}
438
+ # - :included_dirs See {FrameWork::FilterSet#included_dirs}
439
+ # - :excluded See {FrameWork::FilterSet#excluded}
440
+ # - :excluded_dirs See {FrameWork::FilterSet#excluded_dirs}
441
+ # @return [NilClass]
442
+ def watch(*args, &block)
443
+
444
+ # ya know, I couldn't make the @overload statement above work correctly, so, i rigged it.
445
+ # arguments are processed in expected order: right to left.
446
+ config = args.last.kind_of?(Hash) ? args.pop : {}
447
+ config = {runnable: false, standard_map: true}.merge(config)
448
+
449
+ # developer may specify included outside of the options Hash
450
+ #
451
+ # here /^books/ is considered the included filter
452
+ # watch "my_files*", /^books/, excluded: /bikes/
453
+ #
454
+ # here [/^books/, /^trucks/] is considered the included filter
455
+ # watch "my_files*", [/^books/, /^trucks/], excluded_dirs: /unit/
456
+ #
457
+ use_arg_as_included = false
458
+ if (args.last.kind_of?(Symbol) && args.last.eql?(:all)) || args.last.kind_of?(Regexp)
459
+ use_arg_as_included = true
460
+
461
+ elsif args.last.kind_of?(Array)
462
+ args.last.each do |item|
463
+ if item.kind_of?(Regexp) || (item.kind_of?(Symbol) && item.eql?(:all))
464
+ use_arg_as_included = true
465
+ break
466
+ end
467
+ end
468
+ end
469
+
470
+ if use_arg_as_included
471
+ config[:included] = args.pop
472
+ end
473
+
474
+ pattern = args.last.kind_of?(String) || args.last.kind_of?(Array) ? args.pop : nil
475
+
476
+ unless pattern.blank?
477
+ config[:pattern] = pattern
478
+
479
+ framework = self.get_framework(self.current_framework)
480
+ config[:autorun] = config[:autorun].nil? ? framework[:autorun] : config[:autorun]
481
+ config[:autorun] = false unless config[:runnable]
482
+
483
+ config[:watch_basedir] = config[:watch_basedir].blank? ? framework[:watch_basedir] : config[:watch_basedir]
484
+ config[:runnable_basedir] = config[:runnable_basedir].blank? ? framework[:runnable_basedir] : config[:runnable_basedir]
485
+ buffer_config = {}
486
+ buffer_config[:excluded] = framework[:excluded]
487
+ buffer_config[:excluded_dirs] = framework[:excluded_dirs]
488
+ buffer_config[:included] = framework[:included]
489
+ buffer_config[:included_dirs] = framework[:included_dirs]
490
+ config = buffer_config.merge(config)
491
+
492
+ prev_value = self.current_watch_config
493
+
494
+ self.current_watch_config = FrameWork::WatchConfig.new(config)
495
+
496
+ yield self.current_watch_config if block_given?
497
+
498
+ # i know it seems like a waste to grab this variable again, but, things may have changed
499
+ # by the time we reach this point since we just executed a block, so, i'm grabbing it to be safe.
500
+ framework = self.get_framework(self.current_framework)
501
+ framework[:watch_configs] = [] unless framework[:watch_configs].kind_of?(Array)
502
+ framework[:watch_configs].push(self.current_watch_config)
503
+
504
+ self.current_watch_config = prev_value
505
+
506
+ return nil
507
+ end
508
+
509
+ end
510
+
511
+ ##################################################################################
512
+ # A wrapper function for {DuckTest::Config#watch DuckTest::Config#watch}. The only difference
513
+ # is that {FrameWork::WatchConfig#runnable} is forced set to true and the :watch_basedir is
514
+ # set to match the current framework :runnable_basedir. That way all of the filter sets and mappings
515
+ # will work as expected.
516
+ # @return [NilClass]
517
+ def runnable(*args, &block)
518
+ args.push({}) unless args.last.kind_of?(Hash)
519
+ args.last[:runnable] = true
520
+ if args.last[:watch_basedir].blank?
521
+ args.last[:watch_basedir] = self.get_framework(self.current_framework)[:runnable_basedir]
522
+ end
523
+ watch(*args, &block)
524
+ end
525
+
526
+ ##################################################################################
527
+ # Create a map between non-runnable and runnable tests.
528
+ # {include:file:MAPS.md}
529
+ def map(sub_directory = nil, file_name = nil, options = {}, &block)
530
+ config = {}
531
+ config[:watch_basedir] = self.current_watch_config.watch_basedir unless self.current_watch_config.watch_basedir.blank?
532
+ config[:runnable_basedir] = self.current_watch_config.runnable_basedir unless self.current_watch_config.runnable_basedir.blank?
533
+ config.merge!(options)
534
+ map = DuckTest::FrameWork::Map.new(sub_directory, file_name, config, &block)
535
+ self.current_watch_config.maps.push(map) if map.valid?
536
+ return map
537
+ end
538
+
539
+ ##################################################################################
540
+ # Creates standard mappings between non-runnable and runnable tests for the current framework.
541
+ def standard_maps
542
+
543
+ case self.current_framework
544
+ when :testunit
545
+ map /^controllers/ do
546
+ target /^unit/ do
547
+ file_name do |value, cargo|
548
+ buffer = File.basename(cargo, ".rb").gsub("s_controller", "")
549
+ value =~ /#{buffer}_test.rb/ ? true : false
550
+ end
551
+ end
552
+ target /^functional/ do
553
+ file_name do |value, cargo|
554
+ buffer = File.basename(cargo, ".rb").gsub("_controller", "")
555
+ value =~ /#{buffer}_controller_test.rb/ ? true : false
556
+ end
557
+ end
558
+ end
559
+ map /^models/ do
560
+ target /^unit/ do
561
+ file_name do |value, cargo|
562
+ value =~ /#{File.basename(cargo, ".rb")}_test.rb/ ? true : false
563
+ end
564
+ end
565
+ target /^functional/ do
566
+ file_name do |value, cargo|
567
+ value =~ /#{File.basename(cargo, ".rb")}s_controller_test.rb/ ? true : false
568
+ end
569
+ end
570
+ end
571
+
572
+ when :rspec
573
+ map /^controllers/ do
574
+ target /^models/ do
575
+ file_name do |value, cargo|
576
+ buffer = File.basename(cargo, ".rb").gsub("s_controller", "")
577
+ value =~ /#{buffer}_spec.rb/ ? true : false
578
+ end
579
+ end
580
+ target /^controllers/ do
581
+ file_name do |value, cargo|
582
+ buffer = File.basename(cargo, ".rb").gsub("_controller", "")
583
+ value =~ /#{buffer}_controller_spec.rb/ ? true : false
584
+ end
585
+ end
586
+ end
587
+ map /^models/ do
588
+ target /^models/ do
589
+ file_name do |value, cargo|
590
+ value =~ /#{File.basename(cargo, ".rb")}_spec.rb/ ? true : false
591
+ end
592
+ end
593
+ target /^controllers/ do
594
+ file_name do |value, cargo|
595
+ value =~ /#{File.basename(cargo, ".rb")}s_controller_spec.rb/ ? true : false
596
+ end
597
+ end
598
+ end
599
+ end
600
+
601
+ end
602
+
603
+ ##################################################################################
604
+ # Sets the log level for the ducklog.
605
+ # @return [NilClass]
606
+ def log_level(value)
607
+ Logger.log_level = value
608
+ return nil
609
+ end
610
+
611
+ ##################################################################################
612
+ # Sets a block to run prior to loading any test files that have changed and are in the queue.
613
+ # @return [NilClass]
614
+ def pre_load(&block)
615
+ if block_given?
616
+ self.get_framework(self.current_framework)[:pre_load] = block
617
+ end
618
+ return nil
619
+ end
620
+
621
+ ##################################################################################
622
+ # Sets a block to run prior to running any test files that have changed and are in the queue.
623
+ # @return [NilClass]
624
+ def pre_run(&block)
625
+ if block_given?
626
+ self.get_framework(self.current_framework)[:pre_run] = block
627
+ end
628
+ return nil
629
+ end
630
+
631
+ ##################################################################################
632
+ # Sets a block to run prior to loading any test files that have changed and are in the queue.
633
+ # @return [NilClass]
634
+ def post_load(&block)
635
+ if block_given?
636
+ self.get_framework(self.current_framework)[:post_load] = block
637
+ end
638
+ return nil
639
+ end
640
+
641
+ ##################################################################################
642
+ # Sets a block to run prior to running any test files that have changed and are in the queue.
643
+ # @return [NilClass]
644
+ def post_run(&block)
645
+ if block_given?
646
+ self.get_framework(self.current_framework)[:post_run] = block
647
+ end
648
+ return nil
649
+ end
650
+
651
+ end
652
+ end
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+