module TestBelt::RakeTasks

Constants

FILE_SUFFIX

Public Class Methods

for(test_namespace = :test) click to toggle source
# File lib/test_belt/rake_tasks.rb, line 49
def for(test_namespace = :test)
  self.irb_task(test_namespace.to_s)
  self.to_tasks(test_namespace.to_s)
end
irb_task(path) click to toggle source
# File lib/test_belt/rake_tasks.rb, line 54
def irb_task(path)
  irb_file = File.join(path, "irb.rb")
  if File.exist?(irb_file)
    desc "Open irb preloaded with #{irb_file}"
    task :irb do
      sh "irb -rubygems -r ./#{irb_file}"
    end
  end
end
to_tasks(path) click to toggle source
# File lib/test_belt/rake_tasks.rb, line 64
def to_tasks(path)
  suite_name = File.basename(path)

  # define a rake test task for all top-level test files at this path
  if !Dir.glob(File.join(path, "**/*#{FILE_SUFFIX}")).empty?
    TestTask.new(suite_name.to_sym) do |t|
      file_location = suite_name == path ? '' : " for #{File.join(path.split(File::SEPARATOR)[1..-1])}"
      t.description = "Run all tests#{file_location}"
      t.test_files = FileList["#{path}/**/*#{FILE_SUFFIX}"]
    end.to_task
  end

  namespace suite_name.to_s do
    # define rake test tasks for each top-level test file individually
    Dir.glob(File.join(path, "*#{FILE_SUFFIX}")).each do |test_file|
      test_name = File.basename(test_file, FILE_SUFFIX)
      TestTask.new(test_name.to_sym) do |t|
        t.description = "Run tests for #{[path.split(File::SEPARATOR), test_name].flatten[1..-1].join(':')}"
        t.test_files = FileList[test_file]
      end.to_task
    end

    # recursively define rake test tasks for each file
    # in each top-level directory
    Dir.glob(File.join(path, "*/")).each do |test_dir|
      self.to_tasks(test_dir)
    end
  end
end