Easily run Ruby tests with Sublime Text 2

Posted on Monday June 25, 2012

One of my favorite text editors is Sublime Text 2. Not only does it provide great syntax highlighting but it also allows you to execute bash commands from the program. In this blog, I want to walk you through how to setup Sublime Text 2 to easily run your Ruby tests.

Installation

First you will need to install Sublime Text 2 which you can download here.

Next, go to your Sublime Text 2 Packages directory

  • OS X: ~/Library/Application Support/Sublime Text 2/Packages
  • Windows: %APPDATA%/Sublime Text 2/Packages/
  • Linux: ~/.config/sublime-text-2/Packages/

and clone the repository using the command below:

$ git clone https://github.com/maltize/sublime-text-2-ruby-tests.git RubyTest

Color Setup

Edit the file “Theme - Default/Widget.sublime-settings” in the Library/Application Support/Sublime Text 2/Packages directory:

$ subl "Theme - Default/Widget.sublime-settings" 

In that file, change

"color_scheme": "Packages/Theme - Default/Widgets.stTheme"

to

"color_scheme": "Packages/RubyTest/TestConsole.tmTheme"

Usage

  • Run single ruby test: Command-Shift-R
  • Run all ruby tests from current file: Command-Shift-T
  • Run last ruby test(s): Command-Shift-E
  • Show test panel: Command-Shift-X
  • Check RB, ERB file syntax: Alt-Shift-V
  • Switching between code and test:
    • Single View: Command-.
    • Split View: Command+Ctrl+.

Keys: ‘Command’ (OSX) ‘Ctrl’ (Linux / Windows)