require 'autotest/restart'

Autotest.add_hook :run_command do |_, cmd|
  system "#{Gem.ruby} -rubygems #{Gem.bin_path 'rake', 'rake'} generate"
  cmd.sub! ' -e ', ' -we '
  cmd.sub! "'minitest'", "'minitest', '~> 4.7'"
end

Autotest.add_hook :initialize do |at|
  at.testlib = ''
  at.add_exception '.git'

  def at.path_to_classname s
    sep = File::SEPARATOR
    f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split(sep)
    f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
    f = f.map { |path| path =~ /^Test/ ? path : "Test#{path}"  }
    f.join('::').
      gsub('Rdoc', 'RDoc').
      gsub('Ri', 'RI').
      gsub('Changelog', 'ChangeLog')
  end
end

