NameError:升级到rails3时出现未初始化常量Test::Unit::AssertionFailedError

发布于 2024-09-17 20:18:33 字数 1397 浏览 3 评论 0原文

我正在尝试将我的 Rails 应用程序升级到 Rails3。

当我运行功能测试时,我收到很多 NameError: uninitializedconstant Test::Unit::AssertionFailedError 错误。但单元测试和网站本身似乎运行良好。

Trace 看起来像这样:

NameError: uninitialized constant Test::Unit::AssertionFailedError
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb:52:in `rescue in redirects_to_url?'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb:48:in `redirects_to_url?'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb:35:in `matches?'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/assertions.rb:53:in `assert_accepts'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/context.rb:324:in `block in should'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/context.rb:382:in `call'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/context.rb:382:in `block in create_test_from_should_hash'

Shoulda 和 Amazon S3 gems 都是最新版本。

有什么想法我做错了吗?

I'm trying to upgrade my rails application to Rails3.

When I run functional tests, I get a lot of NameError: uninitialized constant Test::Unit::AssertionFailedError errors. But unit tests and website itself seems to work fine.

Trace looks like this:

NameError: uninitialized constant Test::Unit::AssertionFailedError
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb:52:in `rescue in redirects_to_url?'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb:48:in `redirects_to_url?'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb:35:in `matches?'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/assertions.rb:53:in `assert_accepts'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/context.rb:324:in `block in should'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/context.rb:382:in `call'
/Users/mantas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/shoulda-02520e4/lib/shoulda/context.rb:382:in `block in create_test_from_should_hash'

Both Shoulda and Amazon S3 gems are latest versions.

Any ideas what I am doing wrong?

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

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

发布评论

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

评论(2

回忆追雨的时光 2024-09-24 20:18:33

已报告此问题 http://github.com/thoughtbot/shoulda/issues/issue/ 117.

解决方法(至少让这个错误消失,不确定它是否实际上正常工作)是:

unless defined?(Test::Unit::AssertionFailedError)
  class Test::Unit::AssertionFailedError < ActiveSupport::TestCase::Assertion
  end
end

This has been reported http://github.com/thoughtbot/shoulda/issues/issue/117.

The work around (that at least makes this error go away, not sure if it actually works right) is:

unless defined?(Test::Unit::AssertionFailedError)
  class Test::Unit::AssertionFailedError < ActiveSupport::TestCase::Assertion
  end
end
海未深 2024-09-24 20:18:33

Ash Berlin 的解决方案将使异常消失,但它会使任何 trycatch Test::Unit::AssertionFailedError 的匹配器失败。如果 AssertionFailedErrorActiveSupport::TestCase::Assertion,并且您抛出 ActiveSupport::TestCase::Assertion,您将无法捕获它作为 Test::Unit::AssertionFailedError。他的继承关系是倒退的。相反,请将其放入您的 test_helper.rb 中:

unless defined?(Test::Unit::AssertionFailedError)
  Test::Unit::AssertionFailedError = ActiveSupport::TestCase::Assertion
end

Ash Berlin's solution will make the exception go away, but it will make any matchers that try and catch Test::Unit::AssertionFailedError fail. If AssertionFailedError is an ActiveSupport::TestCase::Assertion, and you throw an ActiveSupport::TestCase::Assertion, you will not catch it as a Test::Unit::AssertionFailedError. He has his inheritance relationship backwards. Instead, put this in your test_helper.rb:

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