Skip to content

Instantly share code, notes, and snippets.

@mattscilipoti
Created November 4, 2009 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattscilipoti/226284 to your computer and use it in GitHub Desktop.
Save mattscilipoti/226284 to your computer and use it in GitHub Desktop.
rake -g spec:recent
#save to ~/.rake/rspec_recent.rake
@usage: `rake -g spec:recent`
# Grab recently touched specs
#from: http://nullcreations.net/entries/general/rspec-on-rails-rake-task-for-recent-specs
#TODO: should this grab list from svn? affter we remove externals?
def recent_specs(touched_since)
recent_specs = FileList['app/**/*'].map do |path|
if File.mtime(path) > touched_since
spec = File.join('spec', File.dirname(path).split("/")[1..-1].join('/'),
"#{File.basename(path, ".*")}_spec.rb")
spec if File.exists?(spec)
end
end.compact
recent_specs += FileList['spec/**/*_spec.rb'].select do |path|
File.mtime(path) > touched_since
end
recent_specs.uniq
end
#TODO: Add ability to pass in touched_since from command line
desc 'Run specs for files which have changed in the last 60 min.'
Spec::Rake::SpecTask.new("spec:recent") do |t|
t.spec_opts = ["--format","specdoc","--color"]
t.spec_files = recent_specs(Time.now - 360) # 60 min.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment