Skip to content

Instantly share code, notes, and snippets.

@coen-hyde
Last active August 29, 2015 14:25
Show Gist options
  • Save coen-hyde/721d12160eaae3082a7e to your computer and use it in GitHub Desktop.
Save coen-hyde/721d12160eaae3082a7e to your computer and use it in GitHub Desktop.
Add this snippet to you bash profile to give you the power of beer.
ROOT_PROJECT_DIR=$HOME/projects/
proot() {
echo $(echo $PWD | sed "s|\($ROOT_PROJECT_DIR[A-Za-z]*\).*|\1|")
}
beer() {
spec=$1
shift
cd $(proot); bundle exec rspec ./spec/$spec $@
}
_beer_completion() {
COMPREPLY=($(compgen -W "$(cd $(proot); find ./spec -type f | sed 's|./spec/||')" ${COMP_WORDS[COMP_CWORD]}))
}
complete -F _beer_completion beer
@coen-hyde
Copy link
Author

That is a short hand for bundle exec rspec with auto complete scoped to $project_root/specs. It can be run within any folder of the current project. ie while in $project_root/app/controllers, running beer controllers/tracker2/activities_controller_spec.rb is the equivalent of cd $project_root; bundle exec rspec specs/controllers/tracker2/activities_controller_spec.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment