Skip to content

Instantly share code, notes, and snippets.

@senorprogrammer
Created November 22, 2011 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senorprogrammer/1387098 to your computer and use it in GitHub Desktop.
Save senorprogrammer/1387098 to your computer and use it in GitHub Desktop.
Pre-commit hooks for Rails projects
#!/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