Ruby 1.9.3 破坏了 rake 测试

发布于 2024-12-12 18:46:05 字数 2496 浏览 0 评论 0 原文

我有一个现有的 Rails 3 项目,它在 ruby​​ 1.9.2-p290 上运行得很好。然而,升级到 ruby​​ 1.9.3-p0 会导致 rake test 吐出以下错误:

/Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: test/unit/**/*_test.rb (ArgumentError)
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:21:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'
/Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: test/functional/**/*_test.rb (ArgumentError)
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:21:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'

这似乎是 rake 问题。但是,当我在 ruby​​ 1.9.3 上创建一个简单的 Rails 项目时,就会发生这样的错误。我该怎么做才能让我的 Rails 项目在 ruby​​ 1.9.3 上运行?

I have an existing rails 3 project that works just fine on ruby 1.9.2-p290. However upgrading to ruby 1.9.3-p0 causes rake test to spit out the following error:

/Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: test/unit/**/*_test.rb (ArgumentError)
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:21:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'
/Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: test/functional/**/*_test.rb (ArgumentError)
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:21:in `run'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
from /Users/zmanji/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'

It seems to be a consequence of this rake issue. However when I create a simple rails project on ruby 1.9.3 so such error occurs. What can I do to get my rails project to run on ruby 1.9.3?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

沧桑㈠ 2024-12-19 18:46:05

添加测试单元 gem 对我有用。

Adding the test-unit gem worked for me.

旧时浪漫 2024-12-19 18:46:05

尝试以下操作(独立):

  1. 使用 test.test_files = FileList['test/unit/**/test*.rb']
  2. 删除 shoulda beta 依赖项。
  3. 使用 test/unit gem。

Try the following (independently):

  1. Use test.test_files = FileList['test/unit/**/test*.rb']
  2. Remove shoulda beta dependency.
  3. Use test/unit gem.
戏舞 2024-12-19 18:46:05

在 ruby​​ 1.9.3 的测试环境中使用 rake 时,shoulda gem 会导致一个普遍问题,这在 此问题

解决方法

使用这一行

gem "shoulda", :require => false

您可以在 Gemfile 中

require 'shoulda'

,然后在测试代码中的某个位置(例如 test/test_helper.rb 如果您使用的是测试单元),您可以将If you are using rspec you should not use根本没有 shoulda gem,您应该使用 shoulda-matchers 这不会导致问题。

The shoulda gem is causing a general problem when using rake in test environment on ruby 1.9.3, this is repported in this issue.

Workaround

You can use this line

gem "shoulda", :require => false

in your Gemfile and then somewhere in your test code (e.g. test/test_helper.rb if you are using test-unit) you can put

require 'shoulda'

If you are using rspec you should not use the shoulda gem at all, you should use the shoulda-matchers and this will not cause problems.

他夏了夏天 2024-12-19 18:46:05

我们将 rake 任务(rake 文件)更改为如下所示

require 'rake/testtask'
  ...
desc "Run all tests in folder tests/test*.rb"
Rake::TestTask.new do |t|
  t.libs << "test"
  t.test_files = FileList['tests/test*.rb']
  t.verbose = true
end

http://rake .rubyforge.org/classes/Rake/TestTask.html

We changed our rake task (rake file) to look like this

require 'rake/testtask'
  ...
desc "Run all tests in folder tests/test*.rb"
Rake::TestTask.new do |t|
  t.libs << "test"
  t.test_files = FileList['tests/test*.rb']
  t.verbose = true
end

based upon: http://rake.rubyforge.org/classes/Rake/TestTask.html

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