Ruby on Rails: /bin/sh: rspec: command not found
The sublime plugin is trying to run the command rspec
using shell /bin/sh
. However, the command is not found because RVM is not loaded in the shell's environment.
As such, the folder where your rspec
executable is located is not in the shell's search path (PATH
environment variable). RVM installs any executable commands that come with gems to someplace like: "/home/your-user/.rvm/gems/ruby-1.9.3-p194@myproject/bin/
" (actual path depending on your gemset, ruby version, and where your OS stores user home directories)
Simple Solution
As mentioned here... you might find that simply executing sublime from a shell environment containing RVM (ie: your project directory) may solve the PATH
problem. However, this requires that you execute your text editor from the command line each time, and that the shell's environment is preserved.
cd ~/src/my-ruby-project
subl .
After much experimentation, I found a way to force the RubyTest plugin to execute rspec
with the correct RVM-controlled environment (with bundler support).
With Bundler Support
Here's the contents of my ~/.config/sublime-text-2/Packages/RubyTest/RubyTest.sublime-settings
file:
{
"erb_verify_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/bundle exec erb -xT - {file_name} | ~/.rvm/bin/rvm-auto-ruby -c",
"ruby_verify_command": "~/.rvm/bin/rvm-auto-ruby -c {file_name}",
"run_ruby_unit_command": "~/.rvm/bin/rvm-auto-ruby -Itest {relative_path}",
"run_single_ruby_unit_command": "~/.rvm/bin/rvm-auto-ruby -Itest {relative_path} -n '{test_name}'",
"run_cucumber_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/bundle exec cucumber {relative_path}",
"run_single_cucumber_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/bundle exec cucumber {relative_path} -l{line_number}",
"run_rspec_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/bundle exec rspec {relative_path}",
"run_single_rspec_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/bundle exec rspec {relative_path} -l{line_number}",
"ruby_unit_folder": "test",
"ruby_cucumber_folder": "features",
"ruby_rspec_folder": "spec",
"ruby_use_scratch" : false,
"save_on_run": false,
"ignored_directories": [".git", "vendor", "tmp"],
"hide_panel": false,
"before_callback": "",
"after_callback": ""
}
This should work as long as you've got bundler in your global gemset, and RVM installed to your home dir (adjust paths as needed if ~/.rvm
does not evaluate correctly, or if bundler
or rvm-auto-ruby
is located somewhere else).
If you are using gemsets you should also add a line like the following to your project's .rvmrc
file:
rvm use ruby-1.9.3-p327@your_project_gemset_name
Without Bundler Support
This assumes you have cucumber
and rspec
installed to the @global gemset of your current ruby:
{
"erb_verify_command": "~/.rvm/bin/rvm-exec $(~/.rvm/bin/rvm current) 1>/dev/null erb -xT - {file_name} | ~/.rvm/bin/rvm-auto-ruby -c",
"ruby_verify_command": "~/.rvm/bin/rvm-auto-ruby -c {file_name}",
"run_ruby_unit_command": "~/.rvm/bin/rvm-auto-ruby -Itest {relative_path}",
"run_single_ruby_unit_command": "~/.rvm/bin/rvm-auto-ruby -Itest {relative_path} -n '{test_name}'",
"run_cucumber_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/cucumber {relative_path}",
"run_single_cucumber_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/cucumber {relative_path} -l{line_number}",
"run_rspec_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/rspec {relative_path}",
"run_single_rspec_command": "~/.rvm/bin/rvm-auto-ruby $(~/.rvm/bin/rvm gemdir | sed -e 's/@.*//' -e 's/$/@global/' )/bin/rspec {relative_path} -l{line_number}",
"ruby_unit_folder": "test",
"ruby_cucumber_folder": "features",
"ruby_rspec_folder": "spec",
"ruby_use_scratch" : false,
"save_on_run": false,
"ignored_directories": [".git", "vendor", "tmp"],
"hide_panel": false,
"before_callback": "",
"after_callback": ""
}
-bash: rails: command not found
As Mattherick suggests, try bundle exec rails c
Rails - Bundle: command not found
It seems that Bundler is not installed in your machine.
You have to install bundler first for that.
1: gem install bundler
2: bundle install
Hope this help you !!!
Rails cron whenever, bundle: command not found
I played around with this all afternoon and couldn't find a better solution. Here is what I have come up with
bundle install --binstubs
and then run
bin/rake daily:stats
Related Topics
Rails - Displaying Foreign Key References in a Form
How to Escape Strings for Terminal in Ruby
Model Using Modules in Rails Application
Cucumber + Webrat + Selenium Guide
Sinatra Static Assets Are Not Found When Using Rackup
How to Ignore Multiline Comments in SASS
Get Link and Href Text from HTML Doc with Nokogiri & Ruby
How to Use Basic Authentication with Httparty in a Rails App
Ruby: How to Group a Ruby Array
Rspec Stubbing Method for Only Specific Arguments
How to Get an Empty Temporary Directory in Ruby on Rails
Rails 3.1 Actioncontroller::Routingerror (No Route Matches [Get] "/Assets/Rails.Png"):
Why Was the Object_Id for True and Nil Changed in Ruby2.0
Watir. Scroll to a Certain Point of the Page