Skip to content

Instantly share code, notes, and snippets.

@voxxit
Created July 25, 2013 18:16
Show Gist options
  • Save voxxit/6082330 to your computer and use it in GitHub Desktop.
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"
#!/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