Skip to content

Instantly share code, notes, and snippets.

@joakimk
Created March 6, 2010 22:30
Show Gist options
  • Save joakimk/323985 to your computer and use it in GitHub Desktop.
Save joakimk/323985 to your computer and use it in GitHub Desktop.
# .autotest in your project or ~/.autotest
# This reduces the time from when you save a file to when autotest runs the tests.
# Optimization: Quicker response time for the files you change more than once
class Autotest
alias_method :find_files_orig, :find_files
def find_files
result = {}
@recently_updated ||= []
@recently_updated.each do |file|
result[file] = File.stat(file).mtime rescue nil
return result if result[file] && self.last_mtime < result[file]
end
find_files_orig
end
alias_method :find_files_to_test_orig, :find_files_to_test
def find_files_to_test(files = find_files)
@recently_updated ||= []
updated = files.select { |filename, mtime| self.last_mtime < mtime }
updated.each do |file|
@recently_updated << file.first unless @recently_updated.include?(file.first)
end
find_files_to_test_orig(files)
end
end
Autotest.add_hook :initialize do |at|
# Makes change detection much faster (but CPU usage higher)
at.sleep = 0.1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment