Will Bridges

Unconditional Wisdom

How To Make Sure Specs Are Passing Before Subversion Commit

I jumped on the Behavior Driven Development (BDD) band wagon for development not to long ago. Also, before that, when doing Test Driven Development (TDD) I worked at this company called Outdoor Central. They had it setup where if you committed code to subversion and the tests failed the whole group would get an email saying that you broke the build. That was entertaining and worked okay. But, what if I don't want a commit to be put in if the specs/tests don't pass. Well, that's why I built a pre-commit hook script in ruby and put in in subversion. Now, when someone checks in the server checks out the most recent version of the respository to a temporary location, applies the subversion changes via 'patch' to the temporary check-out and then runs specs against it. If they don't pass it doesn't let them commit. If it does pass they get to move on right along. It's pretty cool. Further it emails me, the admin, a pretty html report of the rspec results so I can see what's going on. I was thinking about implementing an rcov email with every successful commit too but I don't see a need for it yet. However, if you would like to implement it, go ahead. Heres's the scripts for my pre-commit hook:

#!/bin/sh

# PRE-COMMIT HOOK # Save as 'pre-commit' without the .txt in the hooks directory of the subversion repository

REPOS="$1"REV="$2"

# Might need explicit path to ruby instead of just 'ruby'ruby /path/to/runtests.rb "$REPOS" "$REV"

http://wp.invisiwill.com/files/runtests.rb

 

No comments yet. Be the first.

Leave a reply