Ruby on Rails:/bin/sh:rspec:找不到命令 [英] Ruby on Rails: /bin/sh: rspec: command not found

查看:59
本文介绍了Ruby on Rails:/bin/sh:rspec:找不到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在阅读 Michael Hartl 的 RoR 教程,但在尝试运行 Spork 和 Guard 时卡在第 3 章.尝试运行测试时,我得到:

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: 命令未找到

是的,我确实环顾四周寻找答案,但我没有看到 RubyTest.sublime.settings 文件在哪里,所以我不知道如何编辑它.任何人都可以帮助我解决我的错误吗?

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.sublime.settings 文件

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": ""
}

推荐答案

sublime 插件正在尝试使用 shell /bin/sh 运行命令 rspec.但是,没有找到该命令,因为在 shell 环境中未加载 RVM.

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.

因此,rspec 可执行文件所在的文件夹不在 shell 的搜索路径(PATH 环境变量)中.RVM 将 gems 附带的任何可执行命令安装到某个地方,例如:/home/your-user/.rvm/gems/ruby-1.9.3-p194@myproject/bin/"(实际路径取决于您的 gemset、ruby 版本以及您的操作系统存储用户主目录的位置)

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)

此处所述...您可能会发现只需从包含 RVM 的 shell 环境中执行 sublime(即:您的项目目录)可以解决PATH问题.但是,这要求您每次都从命令行执行文本编辑器,并保留 shell 的环境.

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 .

经过大量实验,我找到了一种方法,可以强制 RubyTest 插件在正确的 RVM 控制环境(支持捆绑程序)下执行 rspec.

After much experimentation, I found a way to force the RubyTest plugin to execute rspec with the correct RVM-controlled environment (with bundler support).

这是我的 ~/.config/sublime-text-2/Packages/RubyTest/RubyTest.sublime-settings 文件的内容:

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": ""
}

只要您在全局 gemset 中有 bundler 并且 RVM 安装到您的主目录,这应该可以工作(如果 ~/.rvm 没有正确评估,则根据需要调整路径,或者如果 bundlerrvm-auto-ruby 位于其他地方).

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,您还应该在项目的 .rvmrc 文件中添加如下一行:

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

无捆绑程序支持

这假设您已将 cucumberrspec 安装到 当前 ruby​​ 的 @global gemset:

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": ""
}

这篇关于Ruby on Rails:/bin/sh:rspec:找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆