1. Copy the source to a directory that is in your path:
#!/usr/bin/env ruby
if ARGV.size < 2
puts "Usage: stakeout.rb
exit 1
end
command = ARGV.shift
files = {}
ARGV.each do |arg|
Dir[arg].each { |file|
files[file] = File.mtime(file)
}
end
loop do
sleep 1
changed_file, last_changed = files.find { |file, last_changed|
File.mtime(file) > last_changed
}
if changed_file
files[changed_file] = File.mtime(changed_file)
puts "=> #{changed_file} changed, running #{command}"
puts system(command)
puts "=> done"
end
end
2. chmod +x stakeout.rb
3. To run:
stakeout.rb "spec bacon_spec.rb" **/*
This will run the spec called back_spec.rb whenever any files found recursively from the current file is changed.
Reference:
Faster TDD with Stakeout.rb