-
-
Save samshull/1169764 to your computer and use it in GitHub Desktop.
Watchr script for Cucumber, Rspec, and Evergreen
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
system('clear') | |
ENV["WATCHR"] = "1" | |
$spec_cmd = "rspec --colour --format nested -d" | |
$evergreen_cmd = "evergreen run ." | |
GROWL = `which growlnotify`.chomp | |
if GROWL.empty? | |
puts "Missing growlnotify command for growl notifications" | |
def growl(passed, title); end | |
else | |
def growl(passed, title) | |
if passed | |
message = 'Watchr: All tests passed' | |
priority = 4 | |
else | |
message = 'Watchr: Tests are failing' | |
priority = 0 | |
end | |
options = "-p #{priority} -n Autotester --image '#{File.expand_path(priority == 0 ? "~/.watchr_images/failed.png" : "~/.watchr_images/passed.png")}' -m '#{message}' '#{title}'" | |
system %(#{GROWL} #{options}) | |
end | |
end | |
def run(cmd) | |
cmd = "bundle exec #{cmd}" | |
system('clear') | |
puts(cmd) | |
system(cmd) | |
end | |
def run_spec(spec) | |
result = run "#{$spec_cmd} #{spec}" | |
growl result, 'rspec' | |
end | |
def run_js_spec(spec) | |
result = run "#{$evergreen_cmd} #{spec}" | |
growl result, 'evergreen' | |
end | |
def run_all_js_specs | |
result = run $evergreen_cmd | |
growl result, 'evergreen' | |
end | |
def run_all_specs | |
result = run "#{$spec_cmd} spec/" | |
growl result, 'rspec' | |
end | |
def related_specs(path) | |
Dir["spec/**/#{File.basename(path).split(".").first}_spec.rb"] | |
end | |
def related_js_specs(path) | |
Dir["spec/javascripts/**/#{File.basename(path).split(".").first}_spec.{js,coffee}"] | |
end | |
def run_all_features | |
result = run "cucumber" | |
growl result, 'cucumber' | |
end | |
def run_feature(feature) | |
result = run "cucumber #{feature}" | |
growl result, 'cucumber' | |
end | |
def run_suite | |
run_all_specs | |
run_all_features | |
end | |
watch('spec/spec_helper\.rb') { run_all_specs } | |
watch('spec/(factories|support)/.*') { run_all_specs } | |
watch('spec/.*_spec\.rb') { |m| run_spec m[0] } | |
watch('spec/javascripts/spec_helper\.(js|coffee)') { run_all_js_specs } | |
watch('spec/javascripts/.*_spec\.(js|coffee)') { |m| run_js_spec(m[0]) } | |
watch('app/javascripts/.*\.js') { |m| related_js_specs(m[0]).each {|f| run_js_spec(f) } } | |
watch('app/.*\.rb') { |m| related_specs(m[0]).each {|tf| run_spec tf } } | |
watch('lib/.*\.rb') { |m| related_specs(m[0]).each {|tf| run_spec tf } } | |
watch('features/(step_definitions|support)/.*') { |m| run_all_features } | |
watch('features/.*\.feature') { |m| run_feature m[0] } | |
# Ctrl-\ | |
Signal.trap 'QUIT' do | |
puts " --- Running all specs ---\n\n" | |
run_all_specs | |
end | |
@interrupted = false | |
# Ctrl-C | |
Signal.trap 'INT' do | |
if @interrupted then | |
@wants_to_quit = true | |
abort("\n") | |
else | |
puts "Interrupt a second time to quit" | |
@interrupted = true | |
Kernel.sleep 1.5 | |
# raise Interrupt, nil # let the run loop catch it | |
run_suite | |
@interrupted = false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment