Created
May 17, 2009 23:55
-
-
Save peterc/113226 to your computer and use it in GitHub Desktop.
Rake task to automatically run something (i.e. specs) when code files are changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rake task to automatically run something (i.e. specs) when code files are changed | |
# By Peter Çoopér | |
# | |
# Motivation: I couldn't get autotest to run on my Sinatra project for some reason but realized | |
# it didn't require overengineering. Just detect when a file is changed and then re-run the specs! | |
# | |
# Examples: | |
# # rake on_update "rake" | |
# # rake on_update "spec spec/user_spec.rb" | |
# | |
# Installation: Just add this Rake task into your Rakefile or whatever task inclusion system | |
# you have set up. | |
# | |
# License: Public domain. | |
desc "Automatically run something when code is changed" | |
task :on_update do | |
require 'find' | |
files = {} | |
loop do | |
changed = false | |
Find.find(File.dirname(__FILE__)) do |file| | |
next unless file =~ /\.rb$/ | |
ctime = File.ctime(file).to_i | |
if ctime != files[file] | |
files[file] = ctime | |
changed = true | |
end | |
end | |
if changed | |
system ARGV[1] | |
puts "\nWaiting for a *.rb change" | |
end | |
sleep 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have you looking into watchr? One benefit I see with watchr is that it's platform agnostic...incase you want to use it in other platforms/systems