module Transpec::SpecFileFinder
Public Instance Methods
base_paths(paths)
click to toggle source
# File lib/transpec/spec_file_finder.rb, line 21 def base_paths(paths) if paths.empty? if Dir.exist?('spec') ['spec'] else fail ArgumentError, 'Specify target files or directories.' end else if paths.all? { |path| inside_of_current_working_directory?(path) } paths else fail ArgumentError, 'Target path must be inside of the current working directory.' end end end
find(paths)
click to toggle source
# File lib/transpec/spec_file_finder.rb, line 9 def find(paths) base_paths(paths).reduce([]) do |file_paths, path| if File.directory?(path) file_paths.concat(ruby_files_in_directory(path)) elsif File.file?(path) file_paths << path elsif !File.exist?(path) fail ArgumentError, "No such file or directory #{path.inspect}" end end end
inside_of_current_working_directory?(path)
click to toggle source
# File lib/transpec/spec_file_finder.rb, line 37 def inside_of_current_working_directory?(path) File.expand_path(path).start_with?(Dir.pwd) end
ruby_files_in_directory(directory_path)
click to toggle source
# File lib/transpec/spec_file_finder.rb, line 41 def ruby_files_in_directory(directory_path) ruby_file_paths = [] Find.find(directory_path) do |path| next unless File.file?(path) next unless File.extname(path) == '.rb' ruby_file_paths << path end ruby_file_paths end