Skip to content

Instantly share code, notes, and snippets.

@icebreaker
Created September 28, 2012 11:39
Show Gist options
  • Select an option

  • Save icebreaker/3799321 to your computer and use it in GitHub Desktop.

Select an option

Save icebreaker/3799321 to your computer and use it in GitHub Desktop.
Auto Test Lite Edition
#!/usr/bin/env ruby
require 'directory_watcher'
# Copyright (c) 2012, Mihail Szabolcs
# Released into the public domain. (http://unlicense.org/)
VERSION = "0.1"
HELP = <<-HELP
AutoTest Lite Edition v#{VERSION}
Usage:
#{File.basename(__FILE__, File.extname(__FILE__))} file [test]
HELP
if ARGV.size < 1
puts HELP
exit
end
watch = true
command = "ruby -I. #{ARGV[0]}"
command+= " -n \"test_#{ARGV[1].gsub(' ', '_')}\"" if ARGV.size == 2
directory = File.expand_path(File.dirname(ARGV[0]))
puts "Watching directory '#{directory}' for changes ..."
puts "Running '#{command}' on every change ..."
dw = DirectoryWatcher.new directory, :glob => "*.rb", :pre_load => true, :interval => 1
dw.add_observer do |*args|
args.each do |event|
system(command)
end
end
trap("INT") do
puts "Bye, bye ..."
watch = false
dw.stop
end
dw.start
while watch
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment