I’m currently going through Michael Hartl’s RoR tutorial and am stuck on Chapter 3 when trying to run Spork and Guard. When trying to run tests I get:
/bin/sh: rspec: command not found
Yes, I did look around for an answer but I don’t see where the RubyTest.sublime.settings file is so I don’t know how to edit it. Can anyone help me out on how to fix my error?
this is my Rubytest.sublime.settings file in my user fodler
{
"erb_verify_command": "bundle exec erb -xT - {file_name} | ruby -c",
"ruby_verify_command": "bundle exec ruby -c {file_name}",
"run_ruby_unit_command": "bundle exec ruby -Itest {relative_path}",
"run_single_ruby_unit_command": "bundle exec ruby -Itest {relative_path} -n '{test_name}'",
"run_cucumber_command": "bundle exec cucumber {relative_path}",
"run_single_cucumber_command": "bundle exec cucumber {relative_path} -l{line_number}",
"run_rspec_command": "bundle exec rspec {relative_path}",
"run_single_rspec_command": "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": ""
}
The sublime plugin is trying to run the command
rspecusing 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
rspecexecutable is located is not in the shell’s search path (PATHenvironment 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
PATHproblem. However, this requires that you execute your text editor from the command line each time, and that the shell’s environment is preserved.After much experimentation, I found a way to force the RubyTest plugin to execute
rspecwith 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-settingsfile: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
~/.rvmdoes not evaluate correctly, or ifbundlerorrvm-auto-rubyis located somewhere else).If you are using gemsets you should also add a line like the following to your project’s
.rvmrcfile:Without Bundler Support
This assumes you have
cucumberandrspecinstalled to the @global gemset of your current ruby: