Permalink
Browse files

autodetect rbenv and rvm

  • Loading branch information...
1 parent f12adb9 commit c7d37d7e18b9b56efa2c93a7b1897ee5fc49645e @gs gs committed Dec 20, 2012
Showing with 21 additions and 1 deletion.
  1. +5 −1 README.md
  2. +3 −0 RubyTest.sublime-settings
  3. +13 −0 run_ruby_test.py
View
@@ -60,7 +60,11 @@ Additional Features:
-------------------
Below features can be enabled by editing `RubyTest.sublime-settings`
-- Save on Run - if enabled then files will be automatically saved when running the test
+- RVM / RBENV auto detect (thx to @bronson) - feature is disabled by default, but if you enable it then be sure that your settings file is configure to use `bundle exec` (refer to https://github.com/maltize/sublime-text-2-ruby-tests#bundler-support)
+ `"check_for_rbenv": true`
+ `"check_for_rvm": true`
+
+- Save on Run - if enabled then all files will be automatically saved before running the test
`"save_on_run": true`
- Use Scratch - test output in new tab
@@ -15,6 +15,9 @@
"ruby_cucumber_folder": "features",
"ruby_rspec_folder": "spec",
+ "check_for_rbenv": false,
+ "check_for_rvm": false,
+
"ruby_use_scratch" : false,
"save_on_run": false,
"ignored_directories": [".git", "vendor", "tmp"],
View
@@ -112,10 +112,21 @@ def load_config(self):
global HIDE_PANEL; HIDE_PANEL = s.get("hide_panel")
global BEFORE_CALLBACK; BEFORE_CALLBACK = s.get("before_callback")
global AFTER_CALLBACK; AFTER_CALLBACK = s.get("after_callback")
+ global COMMAND_PREFIX; COMMAND_PREFIX = False
+
+ rbenv_cmd = os.path.expanduser('~/.rbenv/bin/rbenv')
+ rvm_cmd = os.path.expanduser('~/.rvm/bin/rvm-auto-ruby')
+ if s.get("check_for_rbenv") and self.is_executable(rbenv_cmd):
+ COMMAND_PREFIX = rbenv_cmd + ' exec'
+ elif s.get("check_for_rvm") and self.is_executable(rvm_cmd):
+ COMMAND_PREFIX = rvm_cmd + ' -S'
if s.get("save_on_run"):
self.window().run_command("save_all")
+ def is_executable(self, path):
+ return os.path.isfile(path) and os.access(path, os.X_OK)
+
def save_test_run(self, command, working_dir):
s = sublime.load_settings("RubyTest.last-run")
s.set("last_test_run", command)
@@ -126,6 +137,8 @@ def save_test_run(self, command, working_dir):
def run_shell_command(self, command, working_dir):
if not command:
return False
+ if COMMAND_PREFIX:
+ command = COMMAND_PREFIX + ' ' + command
if BEFORE_CALLBACK:
os.system(BEFORE_CALLBACK)
if AFTER_CALLBACK:

0 comments on commit c7d37d7

Please sign in to comment.