diff --git a/README.md b/README.md index deacfc5..67a1342 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,8 @@ Additional Features: ------------------- Below features can be enabled by editing `RubyTest.sublime-settings` -- 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) +- CHRUBY / 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_chruby: true` `"check_for_rbenv": true` `"check_for_rvm": true` @@ -95,34 +96,35 @@ Settings: { "erb_verify_command": "erb -xT - {file_name} | ruby -c", "ruby_verify_command": "ruby -c {file_name}", - + "run_ruby_unit_command": "ruby -Itest {relative_path}", "run_single_ruby_unit_command": "ruby -Itest {relative_path} -n '{test_name}'", - + "run_cucumber_command": "cucumber {relative_path}", "run_single_cucumber_command": "cucumber {relative_path} -l{line_number}", - + "run_rspec_command": "rspec {relative_path}", "run_single_rspec_command": "rspec {relative_path} -l{line_number}", - + "ruby_unit_folder": "test", "ruby_cucumber_folder": "features", "ruby_rspec_folder": "spec", - + + "check_for_chruby": false, "check_for_rbenv": false, "check_for_rvm": false, "check_for_bundler": false, "check_for_spring": false, - + "ruby_use_scratch" : false, "save_on_run": false, "ignored_directories": [".git", "vendor", "tmp"], - + "hide_panel": false, - + "before_callback": "", "after_callback": "", - + "theme": "Packages/RubyTest/TestConsole.hidden-tmTheme", "syntax": "Packages/RubyTest/TestConsole.tmLanguage" } diff --git a/RubyTest.sublime-settings b/RubyTest.sublime-settings index f86c09a..3fc962b 100644 --- a/RubyTest.sublime-settings +++ b/RubyTest.sublime-settings @@ -15,6 +15,7 @@ "ruby_cucumber_folder": "features", "ruby_rspec_folder": "spec", + "check_for_chruby": false, "check_for_rbenv": false, "check_for_rvm": false, "check_for_bundler": false, diff --git a/run_ruby_test.py b/run_ruby_test.py index 82bdacf..02d1963 100644 --- a/run_ruby_test.py +++ b/run_ruby_test.py @@ -131,12 +131,12 @@ def load_config(self): global SYNTAX; SYNTAX = s.get('syntax') global THEME; THEME = s.get('theme') - + chruby = s.get("check_for_chruby") rbenv = s.get("check_for_rbenv") rvm = s.get("check_for_rvm") bundler = s.get("check_for_bundler") spring = s.get("check_for_spring") - if rbenv or rvm: self.rbenv_or_rvm(s, rbenv, rvm) + if chruby or rbenv or rvm: self.chruby_rbenv_or_rvm(s, chruby, rbenv, rvm) if spring: self.spring_support() if bundler: self.bundler_support() @@ -144,17 +144,22 @@ def spring_support(self): global COMMAND_PREFIX COMMAND_PREFIX = COMMAND_PREFIX + " spring " - def rbenv_or_rvm(self, s, rbenv, rvm): - which = os.popen('which rbenv').read().split('\n')[0] - brew = '/usr/local/bin/rbenv' + def chruby_rbenv_or_rvm(self, s, chruby, rbenv, rvm): + chruby_cmd = os.path.expanduser('source /usr/local/opt/chruby/share/chruby/chruby.sh && chruby') + + which_rbenv = os.popen('which rbenv').read().split('\n')[0] + brew_rbenv = '/usr/local/bin/rbenv' rbenv_cmd = os.path.expanduser('~/.rbenv/bin/rbenv') + rvm_cmd = os.path.expanduser('~/.rvm/bin/rvm-auto-ruby') - if os.path.isfile(brew): rbenv_cmd = brew - elif os.path.isfile(which): rbenv_cmd = which + if os.path.isfile(brew_rbenv): rbenv_cmd = brew_rbenv + elif os.path.isfile(which_rbenv): rbenv_cmd = which_rbenv global COMMAND_PREFIX - if rbenv and self.is_executable(rbenv_cmd): + if chruby and self.is_executable(chruby_cmd): + COMMAND_PREFIX = chruby_cmd + ' `[ -f .ruby-version ] && cat .ruby-version || ruby` &&' + elif rbenv and self.is_executable(rbenv_cmd): COMMAND_PREFIX = rbenv_cmd + ' exec' elif rvm and self.is_executable(rvm_cmd): COMMAND_PREFIX = rvm_cmd + ' -S'