Topic: bash script for clearing test database and running tests/specs

This is a bash script that i write to run bundler, drop test database, recreates it, run migrations and runs specs and tests

If anyone find it helpful use it

https://gist.github.com/1357875


#!/bin/sh

WORK_DIR=/Users/tomi/rails_apps/myapp/;
RETURN_DIR=/Users/tomi/my_bash_scripts/; #optional

if [ -r $WORK_DIR ]; then
  cd $WORK_DIR
  echo "Changing directory to $WORK_DIR"
  #ls -l;
  
  
  #   if [ -f ./.rvmrc ]; then
  #       . ./.rvmrc
  #   fi
  rvm current
  read -p "Is this RVM version ok ? Press any key to start continue..."
 
  bundle install; #install gems
 
  RAILS_ENV=test bundle exec rake db:drop; 
  RAILS_ENV=test bundle exec rake db:create; 
  RAILS_ENV=test bundle exec rake db:migrate; 
  bundle exec rspec spec; 
  RAILS_ENV=developmnet bundle exec rake db:migrate;  #rake requires that development enviroment has database updated to run unit tests, comment this if you don't want this feature
  bundle exec rake test; 

  if [ -r $RETURN_DIR ]; then
    echo "Changing directory back to $RETURN_DIR"
    cd $RETURN_DIR;
  fi
else
  echo "Work Directory doesn't exist"
fi 


### bash alias for this script add it into your ~/.bash_profile or ~/.bash_profile ###
### you might need to do chmod 755 /Users/tomi/my_bash_scripts/run_rails_app_tests.sh ###
#  alias run_app_tests='/Users/tomi/my_bash_scripts/run_rails_app_tests.sh'