Skip to content

Instantly share code, notes, and snippets.

@ssaunier
Created December 12, 2012 11:01
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 ssaunier/4266952 to your computer and use it in GitHub Desktop.
Save ssaunier/4266952 to your computer and use it in GitHub Desktop.
Lightweight alternative to guard. Run rspec over spork as you code watching changes to your code base.
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist, no specs to run."
return
end
puts "Running #{file}"
system "bundle exec rspec #{file} --drb --colour"
puts
end
# Obviously rerun tests when spec file is updated
watch("spec/.*/*_spec.rb") do |match|
run_spec match[0]
end
# Run specs for app/ folder
watch("app/(.*/.*).rb") do |match|
run_spec %{spec/#{match[1]}_spec.rb}
end
# Run specs for lib/ folder
watch("^lib/(.*/.*).rb") do |match|
run_spec %{spec/lib/#{match[1]}_spec.rb}
end
group :development, :test do
gem "watchr"
gem "rb-fsevent" # If you are not on MacOSX: https://github.com/guard/guard#efficient-filesystem-handling
gem "spork"
end
desc "Run watchr"
task :watchr do
fork do
sh %{bundle exec spork}
end
sh %{bundle exec watchr .watchr}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment