require 'fileutils' require_relative "base_generator" require "erb" require "find" require "ro_commands/core_ext/string" require "active_support" 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 d = name.split("/").first end return d, f end def constant_name if path r = File.basename(path).gsub(%r{_spec\.rb}) do |m| "" end r.camelize end end def path d, f = get_df #puts "d:#{d} line:#{__LINE__}" if test(?d, 'lib') lib_dirs = Find.find('lib').select do |file| test(?d, file) end dir_full_path = lib_dirs.grep(%r{#{d.implicit}$}).first || 'lib' files = Find.find(dir_full_path).select do |file| if test(?f, file) basename = File.basename file basename.match(%r{^#{f.implicit}}) end end file = files.first.gsub(%r{\.rb}, "") basename = File.basename(file) File.join(dir, dir_full_path, "#{basename}_spec.rb") end end def to super unless test(?f, path) file_write(path) end @created_file = path end end end end end