为什么自动测试不起作用?

时间:2010-11-30 00:11:50

标签: ruby-on-rails ruby autotest zentest

我正在尝试将自动测试用于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

这是宝石环境:

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

这是错误。看起来autotest试图使用其他版本的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

3 个答案:

答案 0 :(得分:2)

我看到两件事:

您的which ruby表示默认值为/usr/bin/ruby,但您的自动测试正在调用/usr/local/bin/ruby

  

sh:/ usr / local / bin / unit_diff:/ usr / local / bin / ruby​​:bad interpreter:没有这样的文件或目录

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

/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作为“bang slash”,或者在命令行上调用东西时明确指向Ruby。这将混淆测试没有尽头。在我的脚本中,我使用它来调用Ruby:

#!/usr/bin/env ruby

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

我是使用RVM管理Mac OS和Linux上的Ruby安装的大力支持者。这使得您无需在默认的/usr/bin红宝石中安装任何内容,甚至可以在/usr/local/bin中添加一个。 RVM将所有内容放在~/.rvm中,使得安装/管理/删除Ruby版本及其相关宝石变得非常容易,甚至可以通过删除该目录来彻底清除它。如果您想尝试一下,Installing RVMGemsets是很好的起点。

答案 1 :(得分:1)

Rails支持似乎不属于ZenTest核心。安装autotest-rails或降级到ZenTest 4.0.0以使其重新运行。

答案 2 :(得分:0)

我必须执行以下操作才能在使用ruby ree-1.8.7 + rbenv获取以下错误后让我的自动测试工作:“rbenv:autotest:command not found”尽管gem表示安装了autotest。然而,即使在重复重新安装自动测试之后,/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

我的Gemfile:

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