require 'fileutils' require_relative "base_generator" require "erb" require "find" module RoCommands module Generators class SpecFile include BaseGenerator class << self def create(name) @name = name FileUtils.mkpath dir tt name end private def name @name ||= "" end def dir @dir ||= 'spec' end # get dir file def get_df if name f = File.basename name r = name.split("/") d = (r - [f]).join("/") end return d, f end def path d, f = get_df #puts "d:#{d} line:#{__LINE__}" if test(?d, 'lib') dir_full_path = Find.find('lib').select do |file| test(?d, file) end.select do |dir| basename = File.basename dir #puts "basename:#{basename} line:#{__LINE__}" basename.match(%r{^#{d.split("").join(".*")}}) end.first #puts "dir_full_path:#{dir_full_path} line:#{__LINE__}" files = Dir[File.join(dir_full_path, '**')].select do |file| basename = File.basename file test(?f, file) and basename.match(%r{^#{f}}) end file = files.first.gsub(%r{\.rb}, "") file = File.basename(file) File.join(dir, dir_full_path, "#{file}_spec.rb") end end def to super unless test(?f, path) file_write(path) end @created_file = path end end end end end