Created
March 9, 2011 22:09
-
-
Save scottharvey/863115 to your computer and use it in GitHub Desktop.
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
# Output information | |
watch('config/routes.rb') { system("clear; rake routes")} | |
# Run migrations | |
# watch('^db/migrate/(.*)\.rb') { |m| check_migration(m[1]) } | |
# # Run SASS | |
# watch('^app/stylesheets/(.*\.sass)') { |m| check_sass(m[1]) } | |
# # Run specific tests | |
watch('^app/(.*)\.rb') { |m| run_test_matching(m[1]) } | |
watch('^app/views/(.*)/(.*)\.haml') { |m| run_test_matching(m[1]) } | |
watch('^spec/(.*)_spec\.rb') { |m| run_test_matching(m[1]) } | |
watch('^features/(.*)\.feature') { |m| run_feature_matching(m[1]) } | |
# Run all tests | |
watch('^spec/spec_helper\.rb') { run_all_tests } | |
# Refresh browser after all haml, js and sass | |
watch('(.*\.haml|.*\.js|.*\.sass)') { refresh_browser } | |
# ================== | |
# = Helper Methods = | |
# ================== | |
def run_test_matching(thing_to_match) | |
matches = all_specs.grep(/#{thing_to_match}/i) | |
run matches.join(' ') unless matches.empty? | |
end | |
def all_specs | |
Dir['spec/**/*_spec.rb'] | |
end | |
def run_all_tests | |
@all_tests_passing = run(all_specs.join(' ')) | |
end | |
def run_test_matching(thing_to_match) | |
matches = all_specs.grep(/#{thing_to_match}/i) | |
return if matches.empty? | |
if run(matches.join(' ')) | |
run_all_tests unless @all_tests_pass | |
else | |
show_terminal | |
end | |
end | |
def run(files_to_run) | |
system("clear") | |
puts("Running: #{files_to_run}") | |
system("spec -cfs #{files_to_run}") | |
end | |
# ============ | |
# = Features = | |
# ============ | |
def run_feature_matching(thing_to_match) | |
matches = all_features.grep(/#{thing_to_match}/i) | |
run_feature matches.join(' ') unless matches.empty? | |
end | |
def all_features | |
Dir['features/**/*.feature'] | |
end | |
def run_feature(files_to_run) | |
system("clear") | |
puts("Running: #{files_to_run}") | |
system("cucumber #{files_to_run}") | |
end | |
def check_sass(sass_file) | |
system("clear; compass compile public/stylesheets/sass/#{sass_file}") | |
end | |
def check_migration(migration_file) | |
system("clear; rake db:migrate:reset") | |
run_test_matching(migration_file) | |
end | |
def refresh_browser | |
system("osascript script/refresh_browser.scpt") | |
end | |
def show_terminal | |
system("osascript script/show_terminal.scpt") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment