Sha256: 9708dd76e548499fe77ba1f69cf08c6c8f0542bf347a7509b05ca7b224ed33f6

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

HH = '#' * 22  unless defined?(HH)
H = '#' * 5    unless defined?(H)

def usage
  puts <<-EOS
  Ctrl-\\ or ctrl-4   Running all tests
  Ctrl-C             Exit
  EOS
end

def run(cmd)
  puts "#{HH} #{Time.now} #{HH}"
  puts "#{H} #{cmd}"
  system "/usr/bin/time --format '#{HH} Elapsed time %E' #{cmd}"
end

def run_it(type, file)
  case type
  when 'test';  run %Q(ruby -I"lib:test" -r rubygems #{file})
  else;         puts "#{H} unknown type: #{type}, file: #{file}"
  end
end

def run_all_tests
  puts "\n#{HH} Running all tests #{HH}\n"
  %w[test].each { |dir| run "rake #{dir}"  if  File.exist?(dir) }
end

def run_matching_files(base)
  base = base.split('_').first
  %w[test spec].each { |type|
    files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
    run_it type, files.join(' ')  unless files.empty?
  }
end

%w[test spec].each { |type|
  watch("#{type}/#{type}_helper\.rb") { run_all_tests }
  watch("#{type}/.*/*_#{type}\.rb")   { |match| run_it type, match[0] }
  watch("#{type}/data/(.*)\.rb") { |match|
    m1 = match[1]
    run_matching_files("#{type}/#{m1}/#{m1}_#{type}.rb")
  }
}
%w[rb erb haml slim].each { |type|
  watch("app/.*/(.*)\.#{type}") { |match|
    run_matching_files(match[1])
  }
}

# Ctrl-\ or ctrl-4
    Signal.trap('QUIT') { run_all_tests }
# Ctrl-C
    Signal.trap('INT')  { abort("Interrupted\n") }
usage

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doit-1.0.1 .watchr