Skip to content

Rspec not found #36

Closed
ghost opened this Issue Jan 25, 2012 · 24 comments
@ghost
ghost commented Jan 25, 2012

I'm not sure this is necessarily an issue with the package, but hopefully you can help.

When i run a single rspec test, i get this output:

/bin/sh: rspec: command not found

In the console, i copy and paste the command that as created:

cd '/Users/user/Dropbox/code/app/' && rspec spec/controllers/profile_controller_spec.rb -l 163

When I run that command in Terminal, it works fine. Any why it wouldn't work from Sublime?

@gs
Collaborator
gs commented Jan 25, 2012

Hi,

does the error occures also with running the whole file?

And how do you start sublime 2? Do you start it from console (http://www.sublimetext.com/docs/2/osx_command_line.html) ?

Br,
Grzegorz

@ghost
ghost commented Jan 25, 2012

The error occurs when i run all tests as well.

I aliased the command and kick is off usually from my project directory in Terminal. I just tried to start the app from the applications folder and load it that way and it produced the same result.

@gs
Collaborator
gs commented Jan 25, 2012

Tests does not work if the Sublime is started from applications folder.

But its strange that it does not work when you start it from console in you projects folder.

But does it ever worked for you ?

Br,
Grzegorz

@ghost
ghost commented Jan 25, 2012

I had linked it to a different directory. I recreated the link and started it from the terminal and tests work now. Thanks.

@ghost ghost closed this Jan 25, 2012
@gja
Collaborator
gja commented Jan 30, 2012

This is caused (most likely) because you are using an intrusive ruby management tool, such as RVM.

If you would like this to work better, I suggest using rbenv.

@ghost
ghost commented Jan 30, 2012
@ghost ghost reopened this Feb 14, 2012
@ghost
ghost commented Feb 14, 2012

I got this error again. I haven't changed anything. I have a shortcut created in /usr/local/bin, which is in my PATH.

I got to the project from command line and run "subl ."

when I run the tests using Command - Shift - R, I get "/bin/sh: rspec: command not found". When I look at the console, and see the command generated, if I type is in the console, it works fine.

any ideas?

@ghost
ghost commented Feb 14, 2012

Nevermind.

I ended up just forcing Rspec to run through "bundle exec" in the user settings and it finds it now.

@ghost ghost closed this Feb 14, 2012
@ghost ghost reopened this Feb 14, 2012
@ghost
ghost commented Feb 14, 2012

Despite what I mentioned before, now it says it can't find bundle exec. I'm not sure what else to do at this point. It works right when I change it, and then it seems to break on subsequent opens.

Works fine in the console
cd '/Users/bhilkert/Dropbox/code/meeteor/' && bundle exec rspec spec/requests/my_network_spec.rb -l 15

Doesn't work from within Sublime.

@gs
Collaborator
gs commented Feb 15, 2012

Hi,
To check if I understand correctly your problem:

So you start sublime in your project folder, you have normal structure and you modified the RubyTest.sublime-settings file...when you start test CTRL + ` shows the problem :

'bundle exec' not found?

If I am correct... than I have no idea whats the problem.. :D

@ghost
ghost commented Feb 15, 2012

Yeah that's exactly the steps. Hmmm....

@gja
Collaborator
gja commented Feb 16, 2012
@hale
hale commented Feb 20, 2012

I also have this problem. Running

bundler --binstubs

fixed it for me

@gs
Collaborator
gs commented Feb 21, 2012

Hi,

If rspec is not found and you are using bundler then edit file:
RubyTest.sublime-settings and edit commands by adding bundle exec like below:

"ruby_unit_exec": "bundle exec ruby -Itest",
"ruby_cucumber_exec": "bundle exec cucumber --no-color",
"ruby_rspec_exec": "bundle exec rspec",

@ghost ghost closed this Feb 24, 2012
@preadaptation

(If anyone is still interested:) Another way of setting RubyTest's path to current RVM rspec is:

"run_rspec_command": "$(~/.rvm/bin/rvm gemdir)/bin/rspec {relative_path}",
"run_single_rspec_command": "$(~/.rvm/bin/rvm gemdir)/bin/rspec {relative_path} -l{line_number}",
@bronson
bronson commented Dec 11, 2012

@preadaptation agreed, that seems cleanest. It works for different Rubies being used in different projects and regardless of how your profile is set. Here's how I did the same thing for rbenv:

{
  "run_rspec_command": "$HOME/.rbenv/bin/rbenv exec rspec {relative_path}",
  "run_single_rspec_command": "$HOME/.rbenv/bin/rbenv exec rspec {relative_path} -l{line_number}"
}

It really would be nice to have RubyTest automatically use rvm or rbenv if available.

@yellowaj

@preadaptation that fixed things for me - thanks!

@gja
Collaborator
gja commented Dec 17, 2012

@bronson If you want to be more specific, you can just set tings to
$HOME/.rbenv/shims/rspec {relative_path}

@klippx
klippx commented Dec 19, 2012

@bronson thanks, that worked great for me!

@rayning0

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 130, 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!

@hamxiaoz

@rayning0 I'm having the exact same problem. However, for me, the solution is just simply turning on 'check_for_rvm' and leave everything else unchanged.

'check_for_rvm' : true
@rayning0

Yeah, my problem was I installed RVM in the wrong place, under root (admin), instead of my user account. Thus RVM is not in the expected spot on my Mac hard drive. Just doing "check_for_rvm: true" would not work for me.

@iloveitaly

If you are using rbenv via homebrew and rspec 3.1 use this RubyTest.sublime-settings config:

{
  "run_rspec_command": "eval \"$(/usr/local/bin/rbenv init -)\"; bundle exec rspec {relative_path}",
  "run_single_rspec_command": "eval \"$(/usr/local/bin/rbenv init -)\"; bundle exec rspec {relative_path}:{line_number}"
}
@newmen
newmen commented Feb 20, 2015

I fixed it in #250

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.