Created
September 20, 2013 21:10
-
-
Save acnalesso/6643966 to your computer and use it in GitHub Desktop.
watchr script to automate tests
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
#-*- ruby -*- | |
# | |
# MAKE SURE YOU CHANGE THE YOUR TESTS DIR | |
# AND YOUR LIB DIR | |
# | |
# Run me with: | |
# $ watchr specs.watchr | |
# -------------------------------------------------- | |
# Rules | |
# -------------------------------------------------- | |
watch('^CHANGE_TO_YOUR_TESTS_DIR/.*_spec\.rb') { |m| ruby m[0] } | |
watch('^CHANGE_TO_YOUR_LIB_DIR/(.*)\.rb') { |m| ruby "CHANGE_TO_YOUR_TESTS_DIR/#{m[1]}_spec.rb" } | |
watch('^CHANGE_TO_YOUR_TESTS_DIR/minitest_helper\.rb') { ruby tests } | |
# -------------------------------------------------- | |
# Signal Handling | |
# -------------------------------------------------- | |
Signal.trap('QUIT') { ruby tests } # Ctrl-\ | |
Signal.trap('INT' ) { abort("\n") } # Ctrl-C | |
# -------------------------------------------------- | |
# Helpers | |
# -------------------------------------------------- | |
def ruby(*paths) | |
run "ruby #{gem_opt} -I.:CHANGE_TO_YOUR_LIB_DIR:.:CHANGE_TO_YOUR_TESTS_DIR -e'%w( #{paths.flatten.join(' ')} ).each {|p| require p }'" | |
end | |
def tests | |
Dir['CHANGE_TO_YOUR_TESTS_DIR/**/*_spec.rb'] - ['CHANGE_TO_YOUR_TESTS_DIR/ANY_HELPER_NAME.rb'] | |
end | |
def run( cmd ) | |
puts cmd | |
system cmd | |
end | |
def gem_opt | |
defined?(Gem) ? "-rubygems" : "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment