RubyTest in Sublime Text 2

前端 未结 12 1749
逝去的感伤
逝去的感伤 2020-12-12 16:24

I am trying to get RubyTest to work in Sublime Text 2. I followed the Instruction on the Github Readme and get the following error. Does anyone know how I could fix this?

相关标签:
12条回答
  • 2020-12-12 16:48

    I spent many hours struggling with this same problem! I could not get rspec to run within Sublime Text 2, using the Michael Hartl "Ruby on Rails Tutorial." It kept saying:

    /bin/sh: rspec: command not found
    

    I finally realized that the RubyTest package (https://github.com/maltize/sublime-text-2-ruby-tests) was looking in the WRONG PLACE for my RVM!

    On my Mac, the path for RubyTest is /Library/Application Support/Sublime Text 2/Packages/Ruby Test

    First, to make RubyTest seek the RVM, I changed the parameter in RubyTest.sublime-settings from

    "check_for_rvm": false, to "check_for_rvm": true,
    

    Then I dug into the Python code of run_ruby_test.py: https://github.com/maltize/sublime-text-2-ruby-tests/blob/master/run_ruby_test.py

    At line 151, inside class BaseRubyTask, it had the wrong path for my RVM:

    rvm_cmd = os.path.expanduser('~/.rvm/bin/rvm-auto-ruby')
    

    I changed it to the full correct path: rvm_cmd = os.path.expanduser('/usr/local/rvm/bin/rvm-auto-ruby')

    If this is not your path, find the correct path by typing

    $ which rvm-auto-ruby and substitute that instead.

    After saving run_ruby_test.py, I went to Terminal, cd to my Rails application directory, and ran spork

    Finally, I opened static_pages_spec.rb in Sublime Text 2. Now all the tests work from it!

    0 讨论(0)
  • 2020-12-12 16:53

    You can see a summary of this issue here: https://github.com/maltize/sublime-text-2-ruby-tests/issues/36

    Essentially, what Jim said was correct, you're running RVM or some other ruby vm manager that similarly monkeys with your PATH. Following the directions from this issue I did the following:

    Install the binaries in my project

    bundle install --binstubs
    

    Add the path to my .bashrc and source it

    echo 'export PATH="./bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    

    Open the sublime project from the command line (so that PATH is available in Sublime Text 2)

    subl .
    
    0 讨论(0)
  • 2020-12-12 16:54

    No, you don't need to change paths, run sublime from command line etc. If you are using RVM, you only have to do this:

    Go to Sublime Text 2, go to preferances-> package settings -> RubyTests

    and pick settings-user or settings-default (depending what you are using) and change line:

    "run_rspec_command": "rspec {relative_path}"
    

    to

    "run_rspec_command": "bundle exec rspec {relative_path}"
    

    And so forth - add bundle exec to all commands

    enter image description here

    0 讨论(0)
  • 2020-12-12 16:58

    This is most likely due to using RVM. What is the output of

    which rspec
    

    on your command line?

    Also of note, just because you've included rspec-rails in a Gemfile, does not mean that 'rspec' is an executable program that your system knows about.

    You can edit the RubyTest.sublime.settings to refer to your particular path to the rspec executable and it should work.

    Unfortunately, this has the nasty side effect of being tied to one particular version of Ruby. If you're using RVM to switch between versions, you'll have to update your sublime.settings.

    One work around, is to run Sublime from the command line.

    0 讨论(0)
  • 2020-12-12 17:03

    This worked for me:

    If you're using RVM, open a project with command line from the project's folder:

    subl .
    

    Then, it'll hook the ruby version and gems.

    0 讨论(0)
  • 2020-12-12 17:03

    Running Sublime Text 2(2165) with RubyTest plugin. Ruby and Gems managed with rbenv (0.3.0).

    First attempt to use RubyTest gave the following error: /bin/sh: rspec: command not found

    From the command line I ran which rspec and it returned no results.

    After some digging, I read that bundle install does not put the executables in your $PATH. Alternative executable paths not picked up by shims sometimes

    In order to use the executible outside the app, I had to delete the gem installed by bundler and then install it manually.

    gem uninstall rspec

    gem install rspec

    followed by

    rbenv rehash (Note you will need to run bundle inside your app so it updates the location of the gem)

    This had to be performed for each version of ruby I have under rbenv control.

    Now when I run

    which rspec

    it is found in the path and RubyTest is able to grab it without any problems.

    fwiw, I had to repeat the steps for cucumber as well. To use all of RubyTests' features, ruby, cucumber and rspec executables need to be in your $PATH (for rbenv it is ~/.rbenv/shims/).

    0 讨论(0)
提交回复
热议问题