热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

RubyonRails:/bin/sh:rspec:命令未找到。-RubyonRails:/bin/sh:rspec:commandnotfound

ImcurrentlygoingthroughMichaelHartlsRoRtutorialandamstuckonChapter3whentryingtoru

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

8 个解决方案

#1


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 Solution

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.

这里提到的…您可能会发现,从包含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 Support

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

#2


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包,而不是仅仅更新它。

#3


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》中。现在所有的测试都是这样的!

#4


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.)

(抱歉,我不太熟悉崇高。)

#5


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

#6


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。

#7


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

#8


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

推荐阅读
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • 本文介绍了三种方法来实现在Win7系统中显示桌面的快捷方式,包括使用任务栏快速启动栏、运行命令和自己创建快捷方式的方法。具体操作步骤详细说明,并提供了保存图标的路径,方便以后使用。 ... [详细]
  • 本文介绍了在Windows系统上使用C语言命令行参数启动程序并传递参数的方法,包括接收参数程序的代码和bat文件的编写方法,同时给出了程序运行的结果。 ... [详细]
  • 本文详细介绍了git常用命令及其操作方法,包括查看、添加、提交、删除、找回等操作,以及如何重置修改文件、抛弃工作区修改、将工作文件提交到本地暂存区、从版本库中删除文件等。同时还介绍了如何从暂存区恢复到工作文件、恢复最近一次提交过的状态,以及如何合并多个操作等。 ... [详细]
  • 解决.net项目中未注册“microsoft.ACE.oledb.12.0”提供程序的方法
    在开发.net项目中,通过microsoft.ACE.oledb读取excel文件信息时,报错“未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序”。本文提供了解决这个问题的方法,包括错误描述和代码示例。通过注册提供程序和修改连接字符串,可以成功读取excel文件信息。 ... [详细]
  • 本文介绍了一种轻巧方便的工具——集算器,通过使用集算器可以将文本日志变成结构化数据,然后可以使用SQL式查询。集算器利用集算语言的优点,将日志内容结构化为数据表结构,SPL支持直接对结构化的文件进行SQL查询,不再需要安装配置第三方数据库软件。本文还详细介绍了具体的实施过程。 ... [详细]
  • 本文介绍了pack布局管理器在Perl/Tk中的使用方法及注意事项。通过调用pack()方法,可以控制部件在显示窗口中的位置和大小。同时,本文还提到了在使用pack布局管理器时,应注意将部件分组以便在水平和垂直方向上进行堆放。此外,还介绍了使用Frame部件或Toplevel部件来组织部件在窗口内的方法。最后,本文强调了在使用pack布局管理器时,应避免在中间切换到grid布局管理器,以免造成混乱。 ... [详细]
  • Iamtryingtocreateanarrayofstructinstanceslikethis:我试图创建一个这样的struct实例数组:letinstallers: ... [详细]
author-avatar
J品1北京天7W乐
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有