Class: Reap::ExTest

Inherits:
Task
  • Object
show all
Defined in:
lib/reap/task/extest.rb

Overview

Test Extraction Task

The Reap extract test task scans every package script looking for =begin test… =end sections. With appropriat headers, it copies these sections to files in the test dir, which then can be run using the Reap test task.

Constant Summary

Constants inherited from Task

Task::RUBY

Instance Method Summary collapse

Methods inherited from Task

#ask, #execute, inherited, #initialize, #initiate, master, #master, #provide_setup_rb, #section, section_required, section_required?, #section_required?, #sh, #task, task_attr, #task_desc, task_desc, #task_help, task_help, task_list, #task_name, task_name, #tell, #use_subsection, verify?

Constructor Details

This class inherits a constructor from Reap::Task

Instance Method Details

#runObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/reap/task/extest.rb', line 42

def run

  # setup

  tst.dir    ||= 'test'
  tst.files  ||= [ 'lib/**/*.rb' ]
  tst.files = [ tst.files ].flatten
  #tst.options ?

  # text extract

  #test_libs = tst.libs.join(':')
  files = FileList.new
  files.include(*tst.files)
  if files.empty?
    tell "No script files found."
    return
  end

  tell "Reap is scanning and copying embedded tests..."

  if tst.dir.strip.empty?
    tell "Test directory must be specified."
    return
  end

  unless File.directory?(tst.dir)
    tell "Test directory doesn't exist: #{File.expand_path( tst.dir )}"
    return
  end

  pbar = Console::ProgressBar.new( 'Extracting', files.size )

  files.each { |file|
    pbar.inc

    testing = extract( file )

    unless testing.strip.empty?
      complete_test = create( testing, file )
      libpath = File.dirname( file )
      testfile = "test_" + File.basename( file )
      fp = File.join(tst.dir,libpath,testfile)
      unless File.directory?( File.dirname( fp ) )
        FileUtils.mkdir_p( File.dirname(fp) )
      end
      File.open( fp, "w" ) { |fw| fw << complete_test }
    end
  }

  pbar.finish

end