Textmate bundle for RSpec.
Ruby Shell
Pull request Compare This branch is 247 commits ahead, 1 commit behind dchelimsky:master.
Latest commit 40ce3d9 Feb 23, 2017 @noniq noniq committed with noniq Use `Executable.find` from the Ruby bundle
This provides exactly the kind of functionality we need to determine how to run rspec :-)


RSpec TextMate Bundle

This bundle works with TextMate 2 and RSpec 3. For TextMate 1 and/or RSpec 1 or 2 please use the legacy versions from the branches rspec1-textmate1 or rspec2, respectively.


Open up TextMate’s preferences, go to “Bundles” and make sure “RSpec” is checked.

Running RSpec examples

Commands for running examples:

  • Run Examples ⌘R: Run all examples in the current spec file.
  • Run Single Example ⇧⌘R: Run the example on the current line (also works for example groups).
  • Run Examples in Selected Files/Directories ⌥⇧⌘R: Run all examples from the files / directories selected in the file browser. If nothing is selected, run all examples in spec/. Hint: ⇧⌘A ⌥⇧⌘R is a quick way to run all specs (⇧⌘A deselects everything in the file browser).
  • Run Again ⌃⌥⌘R: Repeat the last run command (can be example file, single example or examples in selected files).

If your project has an .rspec file in its root, the last two commands – “Run Examples in Selected Files/Directories” and “Run Again” – are available everywhere in your project (even in files that not using the “RSpec” mode).

Configuring TextMate for running examples

The bundle runs RSpec in a subshell. The command to start RSpec is determined as such:

  • If a binstub (bin/rspec) is present, it is used for running RSpec (this works great for preloaders like Spring, too).
  • If there is no binstub, but Gemfile.lock is present, RSpec is run via bundle exec rspec.
  • If there is neither a binstub nor a Gemfile.lock, RSpec is simply run via rspec (not recommended – use only if you know exactly what you’re doing).

Internally the bundle uses Executable.find from the Ruby bundle to detect how to run RSpec. For details see https://github.com/textmate/ruby.tmbundle/blob/master/Support/lib/executable.rb

Running RSpec / Ruby from a subshell means that TextMate must be configured to work with whatever Ruby version manager you're using (rbenv, rvm, …). Normally, this means customizing the $PATH variable. See Defining a $PATH in the TextMate blog for details and caveats.

Setting the base directory for running examples

Per default, RSpec is run from the directory currently designated as “project folder” in TextMate. This can be overriden by setting TM_RSPEC_BASEDIR.

It’s even possible to have different base directories for running RSpec in a single project. Take for example a Rails Engine with the following directory layout:

app/        # Rails app
spec/       # examples for the Rails app
  app/      # Engine
  spec/     # examples for the Engine

The examples for the Rails app should be run from the top-level directory, but the examples for the Engine should be run from my_engine/.

To achieve this, create a file my_engine/.tm_properties with the following line:


This makes sure that TM_RSPEC_BASEDIR is set to the full path of the my_engine/ directory whenever you’re editing a file in this directory (or one of its subdirectories). So if you’re editing my_engine/spec/foo_spec.rb and press ⌘R to run the examples, they will be run from the my_engine/ directory, while running examples in, say, spec/bar_spec.rb are still run from the top-level project directory.


In addition to the standard TextMate shell variables, the RSpec TextMate bundle supports the following:


Set the base directory for running RSpec (defaults to the current “Project Folder”). See “Setting the base directory for running examples” above for more info and an example.


Set a custom formatter other than RSpec's TextMate formatter. Use the full classname, e.g. 'Spec::Core::Formatters::WebKit'


Use this to set RSpec options just as you would in an .rspec file.

RVM Integration

[NOTE: Information in this section may be outdated]

There are lots of ways to configure TextMate to work with rvm, but this is the one that we recommend:

With rvm installed, take the full path to rvm-auto-ruby, found via: which rvm-auto-ruby

Next, set up a TM_RUBY option in TextMate/Preferences/Advanced/Shell Variables that points to the rvm-auto-ruby command.

Learn more at:


Parts of RSpec.tmbundle are based on Florian Weber's TDDMate.


The license of RSpec.tmbundle is the same as RSpec's.