0

我正在尝试使用自动测试进行 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
4

3 回答 3

2

我看到两件事:

which ruby说默认是/usr/bin/ruby,但你的 Autotest 正在调用/usr/local/bin/ruby

sh:/usr/local/bin/unit_diff:/usr/local/bin/ruby:错误的解释器:没有这样的文件或目录

此外,您的路径组织得不好,因为您有重复的条目。我将其拆分为“:”,然后对其进行排序以查找重复项:

/bin
/Library/Frameworks/Python.framework/Versions/Current/bin
/opt/local/bin # <--
/opt/local/bin # <--
/opt/local/sbin
/sbin
/Users/ethan/bin
/usr/bin
/usr/local/bin # <--
/usr/local/bin # <--
/usr/local/git/bin
/usr/local/mysql/bin
/usr/local/oracle/instantclient_10_2
/usr/local/pgsql/bin
/usr/sbin

请注意,您有重复的/opt/local/bin/usr/local/bin目录。这些应该出现在默认/usr/bin目录之前,以便首先找到您“个人”安装的应用程序,因此您应该做一些内务处理。完成后关闭终端会话。打开一个新会话并尝试重新运行您的测试,看看是否有任何改变/改进。

路径组织是问题的一部分,并解释了为什么which ruby指向系统 Ruby。我怀疑这个难题的另一部分是您#!/usr/local/bin/ruby在脚本中用作“斜线”,或者当您在命令行上调用时明确指向该 Ruby。这将无休止地混淆测试。在我的脚本中,我使用它来调用 Ruby:

#!/usr/bin/env ruby

效果很好,因为它使用了在我的路径中首先定义的任何 Ruby,以及下一部分......

我非常支持使用RVM来管理 Mac OS 和 Linux 上的 Ruby 安装。它使您不必在默认/usr/binruby​​ 中安装任何东西,甚至不必费心在/usr/local/bin. RVM 将所有内容都放入其中,~/.rvm并且可以非常轻松地安装/管理/删除 Ruby 版本及其相关的 gem,甚至可以通过删除该目录将其全部删除。如果您想尝试一下,安装 RVMGemsets是不错的起点。

于 2010-11-30T01:01:44.137 回答
1

Rails 支持似乎超出了 ZenTest 的核心。安装autotest-rails或降级到 ZenTest 4.0.0 让它再次工作。

于 2010-11-30T00:20:32.300 回答
0

在使用 ruby​​ ree-1.8.7 + rbenv: "rbenv: autotest: command not found" 得到以下错误后,我必须执行以下操作才能使我的自动测试工作,即使 gem 说安装了自动测试。然而,即使在反复重新安装自动测试之后,/usr/local/rbenv/versions/ree-1.8.7-2012.02/bin/autotest 中的二进制文件也丢失了。

#> gem uninstall ZenTest #all versions
#> gem uninstall autotest autotest-fsevent autotest-growl autotest-rails
#> bundle install

我的宝石文件:

group :test,:development do
  gem 'factory_girl_rails', '1.0'
  gem 'mocha','~> 0.12.1', :require => false #for mocking data
  gem 'ZenTest', '4.8.2' #DON'T USE 4.8.3 with Rails 3.2!
  gem 'autotest', '~> 4.4.6'
  gem 'autotest-fsevent','~> 0.2.8'
  gem 'autotest-rails', '~> 4.1.2'
  gem 'autotest-growl', '~> 0.2.16'
end
于 2013-02-22T19:58:18.077 回答