Skip to content

Instantly share code, notes, and snippets.

@danwoolley
Last active October 12, 2015 21:48
Show Gist options
  • Save danwoolley/4092207 to your computer and use it in GitHub Desktop.
Save danwoolley/4092207 to your computer and use it in GitHub Desktop.
Set up Sublime Text 2 for rspec with rvm
*** Now much simpler. Just follow additional features at https://sublime.wbond.net/packages/RubyTest and turn on check_for_rvm ***
Based on http://rubenlaguna.com/wp/2012/02/01/sublime-text-2-rvm-rspec but with some critical changes.
1. Create $HOME/bin/sublime_rspec.rb:
---------------------------------------
#!/usr/bin/env ruby
file = File.expand_path(ARGV[0] || (STDERR.puts('you must specify a ruby file'); exit(-1)))
dir = File.dirname file
while dir.size > 1
if File.exist?(dir + '/.rvmrc')
to_exec = "source #{dir}/.rvmrc; bundle exec rspec #{file} #{ARGV[1]}"
puts to_exec
exec(to_exec)
else
dir = dir.sub(/\/[^\/]*$/, '')
end
end
puts "Could not find any .rvmrc above #{file}"
exit(-1)
---------------------------------------
2. Make it executable:
chmod +x ~/bin/sublime_rspec.rb
3. Install the RubyTest package:
Shift-Cmd-p, Package Install, RubyTest
4. Modify ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/RubyTest/RubyTest.sublime-settings:
"run_rspec_command": "$HOME/bin/sublime_rspec.rb {relative_path}",
"run_single_rspec_command": "$HOME/bin/sublime_rspec.rb {relative_path} -l{line_number}",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment