lib/cleanser.rb in cleanser-0.2.1 vs lib/cleanser.rb in cleanser-0.3.0

- old
+ new

@@ -4,12 +4,13 @@ options = parse_options(argv) find_polluter(argv, options) ? 0 : 1 end def find_polluter(files, options={}) - failing = files.pop + failing = localize_file(files.pop) expand_folders(files, failing) + files.map! { |f| localize_file(f) } if !files.include?(failing) abort "Files have to include the failing file" elsif files.size < 2 abort "Files have to be more than 2" @@ -71,10 +72,14 @@ files_from_folder(f, pattern(failing)) end end.flatten! end + def localize_file(file) + file.sub(/^#{Regexp.escape(Dir.pwd)}/, "") + end + def files_from_folder(folder, pattern) nested = "{,/*/**}" # follow one symlink and direct children Dir[File.join(folder, nested, pattern)].map{|f|f.gsub("//", "/")} end @@ -113,14 +118,11 @@ end command = if options[:rspec] "bundle exec rspec #{files.join(" ")}#{addition}" else - require = files.map do |f| - f = "./#{f}" unless f.start_with?("/") - "-r #{f.sub(/\.rb$/, "")}" - end.join(" ") - "bundle exec ruby #{require} -e ''#{addition}" + require_list = files.map { |file| file.sub(" ", "\\ ") }.join(" ") + "bundle exec ruby -e '%w[#{require_list}].each { |f| require %{./\#{f}} }'#{addition}" end puts "Running: #{command}" status = system(command) puts "Status: #{status ? "Success" : "Failure"}" status