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

发布于 2024-10-04 16:23:41 字数 2798 浏览 2 评论 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

I'm trying to use autotest for Rails development. It's supposed to run my tests automatically.

Here's my setup:

$ 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

Here's the gem environment:

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

Here's the error. It looks like autotest is trying to use some other version of 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十年九夏 2024-10-11 16:23:41

我看到两件事:

您的 which ruby​​ 表示默认值为 /usr/bin/ruby,但您的自动测试正在调用 /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/bin ruby​​ 中安装任何东西,甚至不必在 /usr/local/bin 中添加一个。 RVM 将所有内容都放在 ~/.rvm 中,并且可以非常轻松地安装/管理/删除 Ruby 版本及其关联的 gem,甚至通过删除该目录将其全部清除。 安装 RVMGemsets 是很好的起点。

I see two things:

Your which ruby says the default is /usr/bin/ruby, but your Autotest is calling /usr/local/bin/ruby.

sh: /usr/local/bin/unit_diff: /usr/local/bin/ruby: bad interpreter: No such file or directory

Also, your path is not organized well because you have duplicated entries. I split it on ':' then sorted it to look for duplicates:

/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

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:

#!/usr/bin/env 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.

口干舌燥 2024-10-11 16:23:41

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.

栖迟 2024-10-11 16:23:41

在 ruby​​ ree-1.8.7 + rbenv 出现以下错误后,我必须执行以下操作才能使自动测试正常工作:“rbenv:自动测试:找不到命令”,即使 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

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.

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

My 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文