Created
February 4, 2011 18:40
-
-
Save ozeias/811527 to your computer and use it in GitHub Desktop.
specs.watchr
This file contains hidden or 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
# Run me with: | |
# | |
# $ watchr specs.watchr | |
# -------------------------------------------------- | |
# Convenience Methods | |
# -------------------------------------------------- | |
def all_spec_files | |
Dir['spec/**/*_spec.rb'] | |
end | |
def run_spec_matching(thing_to_match) | |
matches = all_spec_files.grep(/#{thing_to_match}/i) | |
if matches.empty? | |
puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}" | |
else | |
run matches.join(' ') | |
end | |
end | |
def run(files_to_run) | |
puts("Running: #{files_to_run}") | |
system("clear;script/spec -O spec/spec.opts #{files_to_run}") | |
no_int_for_you | |
end | |
def run_all_specs | |
run(all_spec_files.join(' ')) | |
end | |
def cucumber? | |
Dir.entries(".").include? 'features' | |
end | |
def run_cucumber_scenario(scenario_path) | |
system "cucumber #{scenario_path}" | |
end | |
def run_all_features | |
system('clear;cucumber') | |
end | |
def run_suite | |
run_all_specs | |
run_all_features if cucumber? | |
end | |
# -------------------------------------------------- | |
# Watchr Rules | |
# -------------------------------------------------- | |
watch('^spec/(.*)_spec\.rb') { |m| run_spec_matching(m[1]) } | |
watch('^lib/(.*)\.rb') { |m| run_spec_matching(m[1]) } | |
watch('^app/(.*)\.rb') { |m| run_spec_matching(m[1]) } | |
watch('^app/(.*)\.erb') { |m| run_spec_matching(m[1]) } | |
watch('^lib/(.*)\.rb') { |m| run_spec_matching(m[1]) } | |
watch('^spec/spec_helper\.rb') { run_all_specs } | |
watch('^spec/support/.*\.rb') { run_all_specs } | |
watch('^features/.*\.feature') { |m| run_cucumber_scenario(m[0]) } if cucumber? | |
# -------------------------------------------------- | |
# Signal Handling | |
# -------------------------------------------------- | |
def no_int_for_you | |
@sent_an_int = nil | |
end | |
Signal.trap 'INT' do | |
if @sent_an_int then | |
puts " A second INT? Ok, I get the message. Shutting down now." | |
exit | |
else | |
puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again." | |
@sent_an_int = true | |
Kernel.sleep 1.5 | |
run_suite | |
end | |
end | |
# vim:ft=ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment