lib/cleanser.rb in cleanser-0.1.0 vs lib/cleanser.rb in cleanser-0.2.0

- old
+ new

@@ -8,13 +8,13 @@ def find_polluter(files, options={}) failing = files.pop expand_folders(files, failing) if !files.include?(failing) - abort "Files have to include the failing file, use the copy helper" + abort "Files have to include the failing file" elsif files.size < 2 - abort "Files have to be more than 2, use the copy helper" + abort "Files have to be more than 2" elsif !success?([failing], options) abort "#{failing} fails when run on it's own" elsif success?(files, options) abort "tests pass locally" else @@ -50,30 +50,39 @@ Options: BANNER opts.on("-r", "--rspec", "RSpec") { options[:rspec] = true } opts.on("-h", "--help", "Show this.") { puts opts; exit } - opts.on("-v", "--version", "Show Version"){ require 'cleanser/version'; puts Cleanser::VERSION; exit} + opts.on("-v", "--version", "Show Version") do + require 'cleanser/version' unless defined?(Cleanser::VERSION) + puts Cleanser::VERSION; exit + end end.parse!(argv) options end def expand_folders(files, failing) files.map! do |f| - File.file?(f) ? f : files_from_folder(f, pattern(failing)) + if File.file?(f) + f + elsif f =~ /".+"/ + f.split(/, ?/).map { |f| f.tr('"', '') } + else + files_from_folder(f, pattern(failing)) + end end.flatten! 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 def pattern(test) - base = test.split($/).last + base = File.basename(test) if base =~ /^test_/ - "#{$1}*" + "#{$&}*" elsif base =~ /(_test|_spec)\.rb/ "*#{$1}.rb" else "*" end @@ -99,10 +108,14 @@ def success?(files, options) command = if options[:rspec] "bundle exec rspec #{files.join(" ")}" else - "bundle exec ruby #{files.map { |f| "-r./#{f.sub(/\.rb$/, "")}" }.join(" ")} -e ''" + require = files.map do |f| + f = "./#{f}" unless f.start_with?("/") + "-r #{f.sub(/\.rb$/, "")}" + end.join(" ") + "bundle exec ruby #{require} -e ''" end puts "Running: #{command}" status = system(command) puts "Status: #{status ? "Success" : "Failure"}" status