Created
June 5, 2016 21:49
-
-
Save corajr/ff6658bceffe37bfef09f91f55e5d323 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
#!/bin/bash | |
# from https://github.com/depy/my-git-hooks/blob/master/run-rspec-test-pre-commit | |
# usage: copy me to .git/hooks/pre-commit | |
# chmod +x .git/hooks/pre-commit | |
# Stash unstaged changes before running tests | |
git stash -q --keep-index | |
# Run tests | |
RUN_TESTS_CMD='rspec' | |
NUM_FAILS=`${RUN_TESTS_CMD} --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! You've broken $NUM_FAILS tests!!!" | |
exit 1 | |
else | |
echo -e "All tests passed. You didn't break anything. Congrats!\n" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment