big*_*ato 13 ruby ruby-on-rails sublimetext2
我目前正在阅读迈克尔·哈特尔的RoR教程,并且在尝试运行Spork和Guard时陷入了第3章.当我尝试运行测试时,我得到:
/bin/sh: rspec: command not found
是的,我确实环顾四周寻找答案,但我没有看到RubyTest.sublime.settings文件在哪里,所以我不知道如何编辑它.任何人都可以帮我解决如何解决我的错误?
这是我的用户fodler中的Rubytest.sublime.settings文件
{
"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": ""
}
Run Code Online (Sandbox Code Playgroud)
Fer*_*Fer 18
现在RubyTest包有一个名为"check_for_rvm"的配置选项,默认情况下被禁用.
您可以编辑~/.config/sublime-text-2/Packages/RubyTest/RubyTest.sublime-settings文件并将其设置为true.这对我有用,没有做任何其他事情.
更新:如果您使用的是PackageControl,则可能需要重新安装RubyTest包,而不仅仅是更新它.
Tri*_*onX 12
sublime插件试图rspec使用shell 运行命令/bin/sh.但是,找不到该命令,因为未在shell的环境中加载RVM.
因此,rspec可执行文件所在的文件夹不在shell的搜索路径(PATH环境变量)中.RVM将任何随宝石一起提供的可执行命令安装到以下位置:" /home/your-user/.rvm/gems/ruby-1.9.3-p194@myproject/bin/"(实际路径取决于您的gemset,ruby版本以及操作系统存储用户主目录的位置)
正如这里提到的......您可能会发现只需从包含RVM的shell环境(即:您的项目目录)执行sublime就可以解决PATH问题.但是,这要求您每次都从命令行执行文本编辑器,并保留shell的环境.
cd ~/src/my-ruby-project
subl .
Run Code Online (Sandbox Code Playgroud)
经过大量实验,我找到了一种方法来强制RubyTest插件rspec在正确的RVM控制环境下执行(具有捆绑器支持).
这是我的~/.config/sublime-text-2/Packages/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": ""
}
Run Code Online (Sandbox Code Playgroud)
只要您在全局gemset中有捆绑器,并且RVM安装到您的home目录(如果~/.rvm未正确评估,或者如果bundler或rvm-auto-ruby位于其他位置,则根据需要调整路径),这应该可以工作.
如果您正在使用gemsets,您还应该在项目的.rvmrc文件中添加如下所示的行:
rvm use ruby-1.9.3-p327@your_project_gemset_name
Run Code Online (Sandbox Code Playgroud)
假设您拥有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": ""
}
Run Code Online (Sandbox Code Playgroud)
我花了很多时间来解决同样的问题!我无法使用Michael Hartl"Ruby on Rails Tutorial"在Sublime Text 2中运行rspec.它不停地说
/bin/sh: rspec: command not found
Run Code Online (Sandbox Code Playgroud)
我终于意识到RubyTest包正在寻找我的RVM的错误位置!
在我的Mac上,RubyTest的路径是 /Library/Application Support/Sublime Text 2/Packages/Ruby Test
首先,使RubyTest寻求RVM,我改变了参数RubyTest.sublime-settings从
"check_for_rvm": false, 至
"check_for_rvm": true,
然后我挖掘了Python的代码run_ruby_test.py.
在第151行,在类BaseRubyTask内部,它的RVM路径错误:
rvm_cmd = os.path.expanduser('~/.rvm/bin/rvm-auto-ruby')
Run Code Online (Sandbox Code Playgroud)
我把它改成了正确的路径:
rvm_cmd = os.path.expanduser('/usr/local/rvm/bin/rvm-auto-ruby')
Run Code Online (Sandbox Code Playgroud)
如果这不是您的路径,请通过键入which rvm-auto-ruby并替换它来找到正确的路径.
保存后run_ruby_test.py,我去了Terminal,cd到我的Rails应用程序目录,然后运行spork
最后,我static_pages_spec.rb在Sublime Text 2中打开了.现在所有测试都可以使用!
| 归档时间: |
|
| 查看次数: |
10585 次 |
| 最近记录: |