为什么自动测试不起作用?
我正在尝试使用自动测试进行 Rails 开发。它应该自动运行我的测试。
这是我的设置:
$ which ruby
/usr/bin/ruby
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
$ rails -v
Rails 2.3.9
autotest-rails (4.1.0)
ZenTest (4.4.0)
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/mysql/bin:/Users/ethan/bin:/opt/local/bin:/usr/local/pgsql/bin:/usr/local/git/bin:/usr/local/oracle/instantclient_10_2
这是 gem 环境:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/ethan/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gemcutter.org"]
- REMOTE SOURCES:
- http://gemcutter.org
这是错误。看起来自动测试正在尝试使用其他版本的 Ruby。
$ autotest
loading autotest/rails
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I.:lib:test -rubygems -e "%w[test/unit test/functional/procurements_controller_test.rb].each { |f| require f }" | unit_diff -u
sh: /usr/local/bin/unit_diff: /usr/local/bin/ruby: bad interpreter: No such file or directory
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:108:in `flush': Broken pipe (Errno::EPIPE)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:108:in `output'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:51:in `setup_mediator'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:39:in `start'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in `run'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit.rb:278
from -e:1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看到两件事:
您的
which ruby
表示默认值为/usr/bin/ruby
,但您的自动测试正在调用/usr/local/bin/ruby< /代码>。
另外,您的路径组织得不好,因为您有重复的条目。我将其拆分为“:”,然后对其进行排序以查找重复项:
请注意,您有重复的
/opt/local/bin
和/usr/local/bin
目录。这些应该出现在默认/usr/bin
目录之前,以便首先找到您的“个人”安装的应用程序,因此您应该做一些整理工作。完成后关闭您的终端会话。打开一个新会话并尝试重新运行测试,看看是否有任何更改/改进。路径组织是问题的一部分,它解释了为什么
which ruby
指向系统 Ruby。我怀疑这个难题的另一部分是您在脚本中使用#!/usr/local/bin/ruby
作为“爆炸斜线”,或者在调用时明确指向该 Ruby命令行。这会让测试变得无休无止。在我的脚本中,我使用它来调用 Ruby:它工作得很好,因为它使用我的路径中首先定义的任何 Ruby,并且在下一部分中......
我非常支持使用 RVM 用于管理 Mac OS 和 Linux 上的 Ruby 安装。它使得您不必在默认的
/usr/bin
ruby 中安装任何东西,甚至不必在/usr/local/bin
中添加一个。 RVM 将所有内容都放在~/.rvm
中,并且可以非常轻松地安装/管理/删除 Ruby 版本及其关联的 gem,甚至通过删除该目录将其全部清除。 安装 RVM 和 Gemsets 是很好的起点。I see two things:
Your
which ruby
says the default is/usr/bin/ruby
, but your Autotest is calling/usr/local/bin/ruby
.Also, your path is not organized well because you have duplicated entries. I split it on ':' then sorted it to look for duplicates:
Notice that you have duplicated
/opt/local/bin
and/usr/local/bin
directories. Those should appear ahead of the default/usr/bin
directory in order for your "personally" installed apps to be located first, so you should do some housekeeping. Once you have done that close your terminal session(s). Open a new session and try rerunning your test and see if anything has changed/improved.The path organization is part of the problem and explains why
which ruby
points to the system Ruby. I suspect another part of this puzzle is that you are using#!/usr/local/bin/ruby
as the "bang slash" in your scripts, or explicitly pointing to that Ruby when you call things on the command-line. That will confuse tests no end. In my scripts I use this to invoke Ruby:which works nicely because it uses whatever Ruby is defined first in my path, and with this next part...
I'm a big proponent for using RVM to manage Ruby installations on Mac OS and Linux. It makes it so you don't have to install anything in your default
/usr/bin
ruby or even bother with adding one in/usr/local/bin
. RVM puts everything in~/.rvm
and makes it really easy to install/manage/remove Ruby versions along with their associated gems, or even blow it all away by deleting that directory. Installing RVM and Gemsets are good starting places if you want to give it a try.Rails 支持似乎超出了 ZenTest 核心的范围。安装 autotest-rails 或降级到 ZenTest 4.0.0 以使其再次工作。
Rails support seems out of the ZenTest core. Install
autotest-rails
or downgrade to ZenTest 4.0.0 to have it working again.在 ruby ree-1.8.7 + rbenv 出现以下错误后,我必须执行以下操作才能使自动测试正常工作:“rbenv:自动测试:找不到命令”,即使 gem 表示已安装自动测试。然而,即使在重复重新安装自动测试之后, /usr/local/rbenv/versions/ree-1.8.7-2012.02/bin/autotest 中的二进制文件仍然丢失。
我的宝石文件:
I had to do the following to get my autotest working after getting the following error with ruby ree-1.8.7 + rbenv: "rbenv: autotest: command not found" even though gem said autotest was installed. The binary in /usr/local/rbenv/versions/ree-1.8.7-2012.02/bin/autotest was missing however, even after repeated reinstalls of autotest.
My Gemfile: