Class: RecursiveRakeTasks
- Inherits:
-
Object
- Object
- RecursiveRakeTasks
- Defined in:
- lib/recursive_rake_tasks.rb
Overview
Recursive Rake Tasks meant for generating rake tasks for all directories which contains *_spec files under given directory.
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Method Summary collapse
-
#create_spec_task(name, files) ⇒ Object
Creates Spec::Rake::SpecTask.new with taglog support.
-
#has_spec_files?(dir) ⇒ Boolean
Checks wheather the given dir contains any spec files or not.
-
#initialize(dir = 'spec') ⇒ RecursiveRakeTasks
constructor
A new instance of RecursiveRakeTasks.
-
#recursive_spec_task(dir) ⇒ Object
Recursively creates rake spec tasks for the given dir and sub dir underneath it.
Constructor Details
#initialize(dir = 'spec') ⇒ RecursiveRakeTasks
Returns a new instance of RecursiveRakeTasks.
12 13 14 |
# File 'lib/recursive_rake_tasks.rb', line 12 def initialize dir='spec' recursive_spec_task dir end |
Instance Method Details
#create_spec_task(name, files) ⇒ Object
Creates Spec::Rake::SpecTask.new with taglog support
34 35 36 37 38 |
# File 'lib/recursive_rake_tasks.rb', line 34 def create_spec_task name, files Spec::Rake::SpecTask.new(name) do |t| t.spec_files = Dir.taglob(files,ENV['TAGS']) end end |
#has_spec_files?(dir) ⇒ Boolean
Checks wheather the given dir contains any spec files or not.
41 42 43 |
# File 'lib/recursive_rake_tasks.rb', line 41 def has_spec_files? dir not Dir.glob("#{dir}/**/*_spec.rb").empty? end |
#recursive_spec_task(dir) ⇒ Object
Recursively creates rake spec tasks for the given dir and sub dir underneath it.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/recursive_rake_tasks.rb', line 16 def recursive_spec_task dir current_context = File.basename(dir) sub_directories = Dir["#{dir}/*/"] spec_files = Dir["#{dir}/*_spec.rb"] create_spec_task(current_context,"#{dir}/**/*_spec.rb") namespace current_context do sub_directories.each do |sub_dir| recursive_spec_task sub_dir if has_spec_files? sub_dir end spec_files.each do |spec_file| create_spec_task(File.basename(spec_file,'_spec.rb'),spec_file) end end end |