Skip to content

Instantly share code, notes, and snippets.

@sinisterchipmunk
Created May 23, 2011 15:04
Show Gist options
  • Save sinisterchipmunk/986835 to your computer and use it in GitHub Desktop.
Save sinisterchipmunk/986835 to your computer and use it in GitHub Desktop.
Quick-and-dirty autotest without installing Autotest
#!/usr/bin/env ruby
class Autotester
MONITOR_MATCH_PATTERN = "**/*.rb"
TEST_COMMAND = "rspec spec"
def cache
@cache ||= {}
end
def rerun
system TEST_COMMAND
end
def timestamp(file)
File.file?(file) && File.stat(file).mtime.to_f
end
def build_cache
cache.clear
Dir[MONITOR_MATCH_PATTERN].each do |fi|
cache[fi] = timestamp(fi)
end
end
def changed?(fi)
!cache.key?(fi) || cache[fi] != timestamp(fi)
rescue
cache.delete(fi)
true
end
def start!
while true
Dir[MONITOR_MATCH_PATTERN].each do |fi|
if changed?(fi)
rerun
build_cache
break # don't want to run for each file
end
end
sleep(1)
end
end
end
Autotester.new.start!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment