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:
我现在正在经历Michael Hartl的RoR教程,在尝试运行Spork和Guard时,我陷入了第三章。在尝试运行测试时,我得到:
/bin/sh: rspec: command not found
/bin/sh: rspec:命令未找到。
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?
是的,我确实四处寻找答案,但我不知道rubytest在哪里。设置文件,所以我不知道如何编辑它。有人能帮我解决这个错误吗?
this is my Rubytest.sublime.settings file in my user fodler
这是我的Rubytest.sublime。设置文件在我的用户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": ""
}
12
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.
卓越的插件试图使用shell /bin/ sh来运行命令rspec。但是,没有找到该命令,因为RVM没有加载到shell的环境中。
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)
因此,您的rspec可执行文件所在的文件夹不在shell的搜索路径中(path环境变量)。RVM安装了任何可执行的命令,这些命令都是带着宝石来的:“/home/your-user/.rvm/gem /ruby-1.9.3-p194@myproject/bin/”(实际路径取决于您的gemset、ruby版本,以及您的OS存储用户主目录的位置)。
Simple SolutionAs 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.
这里提到的…您可能会发现,从包含RVM(即您的项目目录)的shell环境中执行崇高的任务可能会解决路径问题。但是,这要求您每次都从命令行执行文本编辑器,并且保存shell的环境。
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).
经过多次试验,我找到了一种方法,可以强制RubyTest插件执行rspec,并使用正确的rvm控制环境(使用bundler支持)。
With Bundler SupportHere's the contents of my ~/.config/sublime-text-2/Packages/RubyTest/RubyTest.sublime-settings
file:
这是我的~/.config/sublime-text-2/ package /RubyTest/RubyTest的内容。sublime-settings文件:
{
"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).
只要您在您的全局gemset中有bundler,并且RVM安装到您的主目录(如果~/需要调整路径),就应该这样做。rvm没有正确地评估,或者如果bundler或rvm-auto-ruby位于其他地方)。
If you are using gemsets you should also add a line like the following to your project's .rvmrc
file:
如果您使用的是gemset,您还应该在您的项目的.rvmrc文件中添加一条类似的线:
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:
假设您已经将cucumber和rspec安装到当前ruby的@global gemset中:
{
"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": ""
}
17
Now the RubyTest package has a configuration option called "check_for_rvm" that is disabled by default.
现在,RubyTest包有一个名为“check_for_rvm”的配置选项,默认情况下是禁用的。
You can edit your ~/.config/sublime-text-2/Packages/RubyTest/RubyTest.sublime-settings
file and set it to true
. This worked for me without doing anything else.
你可以编辑你的~/.config/sublime-text-2/ package /RubyTest/RubyTest。sublime-settings文件并将其设置为true。这对我没有任何帮助。
Update: If you are using PackageControl you might need to reinstall the RubyTest package, instead of just updating it.
更新:如果您正在使用PackageControl,您可能需要重新安装RubyTest包,而不是仅仅更新它。
5
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
我花了很多时间来解决这个问题!我无法让rspec在卓越的文本2中运行,使用Michael Hartl“Ruby on Rails教程”。它不停地说
/bin/sh: rspec: command not found
I finally realized that the RubyTest package was looking in the WRONG PLACE for my RVM!
我终于意识到RubyTest程序包在错误的地方找我的RVM!
On my Mac, the path for RubyTest is /Library/Application Support/Sublime Text 2/Packages/Ruby Test
在我的Mac上,RubyTest的路径是/库/应用支持/卓越的文本2/包/Ruby测试。
First, to make RubyTest seek the RVM, I changed the parameter in RubyTest.sublime-settings
from
首先,为了让RubyTest寻找RVM,我在RubyTest中修改了参数。sublime-settings从
"check_for_rvm": false,
to "check_for_rvm": true,
"check_for_rvm": false,到"check_for_rvm": true,
Then I dug into the Python code of run_ruby_test.py
.
然后我挖掘了run_ruby_test.py的Python代码。
At line 151, inside class BaseRubyTask, it had the wrong path for my RVM:
在第151行,在class BaseRubyTask中,它对我的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.
如果这不是您的路径,那么通过键入rvm-auto-ruby并替代它来找到正确的路径。
After saving run_ruby_test.py
, I went to Terminal, cd
to my Rails application directory, and ran spork
在保存run_ruby_test。py,我去了终端,cd到我的Rails应用程序目录,然后运行spork。
Finally, I opened static_pages_spec.rb
in Sublime Text 2. Now all the tests work from it!
最后,我打开static_pages_spec。rb在《崇高的文本2》中。现在所有的测试都是这样的!
0
From the terminal, try 'gem list -d rspec'. That should print out any gems you have w/ rspec in the name. If there aren't any, try 'gem install rspec'.
从终端,试试“gem list -d rspec”。这应该打印出你在名字中有w/ rspec的任何宝石。如果没有,试试“gem安装rspec”。
Assuming that, from terminal, you do have rspec installed (which you can verify with "which rspec", etc.), in that case your problem is likely to do with how Sublime is configured. Note the path where rspec is installed and check whether your editor has that in its paths.
假设,从终端,您确实安装了rspec(您可以用“哪个rspec”等来验证),在这种情况下,您的问题可能与如何配置卓越有关。请注意安装rspec的路径,并检查编辑器是否在其路径中。
(Sorry, I'm not familiar with Sublime in particular.)
(抱歉,我不太熟悉崇高。)
0
Refer to the Bundler settings: https://github.com/maltize/sublime-text-2-ruby-tests
参考Bundler设置:https://github.com/maltize/sublime-text-2-ruby-test。
About RubyTest.sublime-settings
, it should be under your home folder somewhere in sublime-test2/Packages/RubyTest folder. In the case of Ubuntu it would be:
关于RubyTest。sublime-settings,它应该在您的主文件夹下,在sublime-test2/ package /RubyTest文件夹中。在Ubuntu的例子中,它是:
~/.config/sublime-text-2/Packages/RubyTest
0
You need to start sublime from terminal within the working directory: example - (goto working directory in terminal, then start sublime from terminal )
你需要从终端开始崇高在工作目录:例子——(在终端转到工作目录,然后从终端开始升华)
cd rails/my_app_dir
subl .
rails cd / my_app_dir subl。
0
For anybody using rbenv, there is also this setting in rubyTest.sublime-settings
which will do the trick:
对于使用rbenv的人来说,rubyTest中也有这个设置。sublime-settings,这将会起作用:
"check_for_rbenv": true
0
if you've used rbenv during installation of Ruby in Mac and have issue with running "rspec" after installation "rspec gem", like: "-bash: rspec: command not found", just refresh it by typing command:
如果您在安装Ruby in Mac时使用了rbenv,并且在安装了“rspec gem”之后出现了运行“rspec”的问题,比如:“-bash: rspec:命令未找到”,只需通过键入命令刷新它:
rbenv rehash