Created
November 22, 2011 21:45
-
-
Save senorprogrammer/1387098 to your computer and use it in GitHub Desktop.
Pre-commit hooks for Rails projects
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
#!/usr/bin/env ruby | |
# Pre-commit hooks to check the code for errant syntax issues, like logging messages, etc. | |
# Chris Cummer | |
# Check to see if I've left any debugging lines in the ruby files | |
def check_for_ruby_debug( flag ) | |
run_cmd( flag, "grep -rls 'puts \">>' ../../app/**/*.rb", "Debug puts found in:" ) | |
end | |
# Check to see if I've left any :focus rspec directives | |
def check_for_rspec_focus( flag ) | |
run_cmd( flag, "grep -rls ', :focus' ../../spec/**/*.rb", "Rspec :focus directive found in:" ) | |
end | |
def run_cmd( flag, cmd, msg ) | |
result = `#{cmd}` | |
if '' != result | |
print_result( msg, result ) | |
flag = true | |
end | |
flag | |
end | |
def print_result( msg, result ) | |
puts "#{msg} \n" | |
puts result | |
puts "\n" | |
end | |
# ------------------------------ Main ------------------------------ # | |
flag = false | |
flag = check_for_ruby_debug( flag ) | |
flag = check_for_rspec_focus( flag ) | |
exit 1 if flag | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment