lib/reap/task/testext.rb in reap-4.0.0 vs lib/reap/task/testext.rb in reap-4.3.1

- old
+ new

@@ -1,7 +1,7 @@ require 'reap/task' -require 'nano/string/margin' +require 'facet/string/margin' # Extract Test Task # # The Reap extract test task scans every package script # looking for =begin testing ... =end sections. @@ -9,13 +9,11 @@ # to files in the test dir, which then can be run # using the Reap test taks. # class Reap::TestExt < Reap::Task - def task_desc - "Extract unit-tests from lib scripts." - end + task_desc "Extract unit-tests from lib scripts." attr_accessor :dir, :files, :options def init @dir ||= 'test' @@ -46,11 +44,13 @@ files.each { |file| $stdout << '.'; $stdout.flush testing = extract( file ) unless testing.strip.empty? complete_test = create( testing, file ) - fp = File.join(@dir,file) + libpath = File.dirname( file ) + testfile = "test_" + File.basename( file ) + fp = File.join(@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 @@ -61,10 +61,10 @@ def extract( file ) return nil if ! File.file?( file ) tests = ""; inside = false fstr = File.read( file ) fstr.split(/\n/).each do |l| - if l =~ /^=[ ]*begin[ ]*testing/ + if l =~ /^=begin[ ]*test/i tests << "\n" inside = true next elsif inside and l =~ /^=[ ]*end/ inside = false