Module: Quarry::Extract
Overview
Extractor is a tool for extracting code from embedded comment blocks.
TODO:
- Should extract_block handle more than the first matching block?
- How can we handle embedded code in standard comments? Eg. #
Instance Method Summary collapse
-
#test_extract(files = nil) ⇒ Object
Extract unit tests.
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/']
35 36 37 38 39 40 41 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 |
# File 'lib/quarry/extract.rb', line 35 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 |