ruby-on-rails – Ruby on Rails:/ bin / sh:rspec:command not found

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Ruby on Rails:/ bin / sh:rspec:command not found前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在通过Michael Hartl的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": ""
}

解决方法

升华插件正在尝试使用shell / bin / sh运行命令rspec.但是,由于RVM没有加载到shell的环境中,所以找不到该命令.

因此,rspec可执行文件所在的文件夹不在shell的搜索路径(PATH环境变量)中. RVM安装任何可执行的命令,与宝石一起放在以下位置:“/home/your-user/.rvm/gems/ruby-1.9.3-p194@myproject/bin/”(实际路径取决于您的gemset,ruby版本,并且您的操作系统存储用户主目录的位置)

简单的解决方

如上所述here …您可能会发现,只需从包含RVM的shell环境(即:您的项目目录)执行升华即可解决PATH问题.但是,这需要您每次从命令行执行文本编辑器,并且保护shell的环境.

cd ~/src/my-ruby-project
subl .

经过多次实验,我发现了一种方法来强制RubyTest插件使用正确的RVM控制环境执行rspec(支持Bundler).

与Bundler支持

以下是我的〜/ .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}","after_callback": ""
}

只要您在全局gemset中有捆绑器,并且将RVM安装到您的家庭目录(只要〜/ .rvm无法正确评估),或者如果bundler或rvm-auto-ruby位于某处其他).

如果您使用gemsets,您还应该在项目的.rvmrc文件添加如下所示的行:

rvm use ruby-1.9.3-p327@your_project_gemset_name

没有Bundler支持

这假设你将黄瓜和rspec安装到您当前的红宝石的@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","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}","after_callback": ""
}

猜你在找的Ruby相关文章