Module: Xact::ExtractAndSave

Extended by:
ExtractAndSave
Included in:
ExtractAndSave
Defined in:
lib/proutils/xact/save.rb

Instance Method Summary collapse

Instance Method Details

#test_extract(files = nil) ⇒ Object

Extract unit tests. This task scans every package script looking for sections of the form:

=begin test
  ...
=end

With appropriate headers, it copies these sections to files in your project’s test/ dir, which then can be run using the Ratchet test task. The exact directory layout of the files to be tested is reflected in the test directory. You can then use project.rb’s test task to run the tests.

files      Files to extract ['lib/**/*.rb']
output     Test directory   ['test/']


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/proutils/xact/save.rb', line 50

def test_extract(files=nil)
  output = 'test/embedded'     # Don't think output should be setable.

  files  = files || 'lib/**/*.rb'
  files = 'lib/**/*.rb' if TrueClass == files
  files = [files].flatten.compact

  filelist = files.collect{ |f| Dir.glob(f) }
  filelist.flatten!
  if filelist.empty?
    puts "No scripts found from which to extract tests."
    return
  end

  FileUtils.mkdir_p(output) unless File.directory?(output)

  #vrunner = VerbosityRunner.new("Extracting", verbosity?)
  #vrunner.setup(filelist.size)

  filelist.each do |file|
    #vrunner.prepare(file)

    testing = extract_test_from_file( file )
    if testing.strip.empty?
      status = "[NONE]"
    else
      complete_test = create_test(testing, file)
      libpath = File.dirname(file)
      testfile = "test_" + File.basename(file)
      fp = File.join(output, libpath, testfile)
      unless File.directory?( File.dirname(fp))
        FileUtils.mkdir_p(File.dirname(fp))
      end
      File.open(fp, "w"){ |fw| fw << complete_test }
      status = "[TEST]"
    end

    #vrunner.complete(file, status)
  end

  #vrunner.finish(
  #  :normal => "#{filelist.size} files had tests extracted.",
  #  :check => false
  #)
end