Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rake task to automatically run something (i.e. specs) when code files are changed
# 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
@daniely

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.