This bundle works with TextMate 2 and RSpec 2 and 3. For TextMate 1 and/or RSpec 1 please use the legacy version from the branch “rspec1-textmate1”.
Open up TextMate’s preferences, go to “Bundles” and make sure “RSpec” is checked.
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).
Using the bundle to run commands means that RSpec is run from a TextMate subprocess. Some caveats apply:
TL;DR: If your project has a binstub (bin/rspec
), make sure you’ve customized TextMate’s $PATH
to play nicely with your Ruby version manager (rbenv, rvm, …). If it has a Gemfile
, the same goes for $TM_RUBY
. If you’re using the Ruby bundled with Mac OS (not recommended), you shouldn’t need to customize anything.
Now here come the gritty details. There are two ways the bundle can run RSpec:
If bin/rspec
is present, the bundle uses that to run RSpec (great for projects using Bundler binstubs or Spring). The binstub is run via a subshell. This shell inherits it’s $PATH
from TextMate (init scripts like .bashrc
are not run), so make sure this is set to work correctly with rbenv, rvm or whatever you’re using. See Defining a $PATH in the TextMate blog for details and caveats.
If no binstub is present, the bundle commands (which are Ruby scripts) run RSpec examples directly from their Ruby process. The important thing to consider here is the version of Ruby used for running the examples:
The bundle commands start ruby via ${TM_RUBY:-ruby} …
, this means:
- If
$TM_RUBY
is set, that is used. (Can be set via Preferences → Variables.) - Otherwise, search
$PATH
for an executable namedruby
and use that. This will most probably result in using the Ruby version bundled with Mac OS, unless you manually customize$PATH
(again, see Defining a $PATH for details and caveats.)
The bundle then tries to determine which version of RSpec to use. Again, there are two options:
- If a
Gemfile
is present, the RSpec version fromGemfile.lock
is used (via Bundler). - If no
Gemfile
is present, the bundle searchesvendor/plugins
andvendor/gems
for a vendored version of RSpec:- If a vendored version is found, it is used.
- If no vendored version is found, the bundle just tries to require RSpec directly. This means that RSpec must be available in Ruby’s
LOAD_PATH
. If you’re using Ruby 1.9 or newer this usually means that the most recent RSpec version installed via rubygems will get used.
If your Gemfile
is located at a non-standard location, you can add --bundler
to a file named .rspec-tm
in your project’s root directory to force the RSpec bundle to use Bundler (you’ll need to make sure BUNDLER_GEMFILE
is set, otherwise Bundler won’t find the Gemfile, too).
You can set the following options in an .rspec-tm
file in the
root directory of your project:
Use Bundler
, even if there is no Gemfile
(in which case you
should have the BUNDLER_GEMFILE
environment variable set).
Don't use Bundler
, even if there is a Gemfile
.
In addition to the standard TextMate shell variables, the RSpec TextMate bundle supports the following:
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.
If you're hacking on rspec yourself, point this to the
rspec-core
project directory for rspec-2, or the rspec
directory for rspec-1.
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:
- http://rvm.io/integration/textmate
- http://groups.google.com/group/rubyversionmanager/browse_thread/thread/64b84bbcdf49e9b?fwc=1&pli=1
Parts of RSpec.tmbundle
are based on Florian Weber's TDDMate.
The license of RSpec.tmbundle
is the same as
RSpec's.