Skip to content

Instantly share code, notes, and snippets.

@corajr
Created June 5, 2016 21:49
Show Gist options
  • Save corajr/ff6658bceffe37bfef09f91f55e5d323 to your computer and use it in GitHub Desktop.
Save corajr/ff6658bceffe37bfef09f91f55e5d323 to your computer and use it in GitHub Desktop.
#!/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