How to start your RSpec / Cucumber / Spork / Watchr test environment with a single command

My Rails 3 test environment consists of RSpec, Cucumber, Spork and Watchr. Additonally I am running rails console and rails server. This means I have to spawn six terminals or on terminal with six tabs. My preferences lean towards the tab solution. I am setting this up just once or maybe twice a day, but in my humble opinion it is pretty annoying to do this by hand.

The first idea coming to mind might be to spawn multiple gnome-terminals in tabs and execute the desired command in each of them. Unfortunately you have to choose whether you would like to execute a command or rather have a bash shell available. If you just pass on the command to gnome-terminal it closes immediately after the command finished. I struggled a few minutes with this but finally I got it to work:

gnome-terminal --tab --title "spork rspec" -e "bash -c "bundle exec spork rspec; exec bash"" 
               --tab --title "spork cucumber" -e "bash -c "bundle exec spork cucumber; exec bash"" 
               --tab --title "watchr" -e "bash -c "bundle exec watchr .watchr; exec bash"" 
               --tab --title "console" -e "bash -c "rails c; exec bash"" 
               --tab --title "server" -e "bash -c "rails s; exec bash""

Just start bash, after the command finished and you are fine. Feels a little bit hacky but works as intended.

I put this into a file, made it executable and start it when I start working on my app. Awesome. Saves 30 seconds each day. :P

Have fun!

  • Josh Shupack

    I did a similar thing for OS X:

    made this an executable file and have it run by default when I start Terminal:

    ls -1d */
    read -n1 -p ‘Pick the app you want to open (by first letter): ‘ first_letter
    echo “”
    if [ -d $first_letter* ]
        then
        app_name=`ls -d1 $first_letter* | head -n1`
        echo $app_name
        osascript -e “tell application “Terminal”
            do script “cd ~/current_apps/$app_name && ../open_script.sh server” in window 1
            set bounds of window 1 to {400, 1, 1025, 1010}
            do script “cd ~/current_apps/$app_name && ../open_script.sh console”
            set bounds of window 1 to {1, 1, 730, 380}
            do script “cd ~/current_apps/$app_name && ../open_script.sh git”
            set bounds of window 1 to {1, 628, 730, 1010}
        end tell”
    else
        echo “Oops, couldn’t find an application starting with ‘$first_letter’”
    fi

    Also created open_script.sh
    if [[ `ruby -v` == *1.9.2* ]]
        then
        rails_command=”rails ”
    else
        rails_command=”./script/”
    fi
    case $1 in
    server)
       $rails_command’server’
       ;;
    console)
       $rails_command’console’
       ;;
    git)
       git pull
       git status
       mate .
       ;;
    *)
      echo “I don’t know how to start ‘$1′”
    esac

    • Anonymous

      I am not sure if there are possibilities for Code-Highlighting in Disqus, maybe you should put your suggestion into a gist and link to it here.

      Anyway, nice Idea and thx for sharing!

  • Josh Shupack

    I did a similar thing for OS X:

    made this an executable file and have it run by default when I start Terminal:

    ls -1d */
    read -n1 -p ‘Pick the app you want to open (by first letter): ‘ first_letter
    echo “”
    if [ -d $first_letter* ]
        then
        app_name=`ls -d1 $first_letter* | head -n1`
        echo $app_name
        osascript -e “tell application “Terminal”
            do script “cd ~/current_apps/$app_name && ../open_script.sh server” in window 1
            set bounds of window 1 to {400, 1, 1025, 1010}
            do script “cd ~/current_apps/$app_name && ../open_script.sh console”
            set bounds of window 1 to {1, 1, 730, 380}
            do script “cd ~/current_apps/$app_name && ../open_script.sh git”
            set bounds of window 1 to {1, 628, 730, 1010}
        end tell”
    else
        echo “Oops, couldn’t find an application starting with ‘$first_letter’”
    fi

    Also created open_script.sh
    if [[ `ruby -v` == *1.9.2* ]]
        then
        rails_command=”rails ”
    else
        rails_command=”./script/”
    fi
    case $1 in
    server)
       $rails_command’server’
       ;;
    console)
       $rails_command’console’
       ;;
    git)
       git pull
       git status
       mate .
       ;;
    *)
      echo “I don’t know how to start ‘$1′”
    esac

    • http://www.nils-haldenwang.de NilsHaldenwang

      I am not sure if there are possibilities for Code-Highlighting in Disqus, maybe you should put your suggestion into a gist and link to it here.

      Anyway, nice Idea and thx for sharing!