Created
July 25, 2013 18:16
-
-
Save voxxit/6082330 to your computer and use it in GitHub Desktop.
Simple Git pre-commit hook for running specs on a Rails project before committing. Install by pasting into .git/hooks/pre-commit, then do "chmod g+x .git/hooks/pre-commit"
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
#!/bin/bash | |
# Stash unstaged changes before running tests | |
git stash -q --keep-index | |
# Run tests | |
NUM_FAILS=`bundle exec rspec --format=progress | grep "example" | grep "fail" | awk {'print $3'}` | |
# Unstash | |
git stash pop -q | |
if [ $NUM_FAILS -ne 0 ] | |
then | |
echo -e "Can't commit; there are $NUM_FAILS broken tests!" | |
exit 1 | |
else | |
echo -e "All tests passed. Committing...\n" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment