【问题标题】:NameError: uninitialized constant Test::Unit::AssertionFailedError when upgrading to rails3NameError:升级到 rails3 时未初始化的常量 Test::Unit::AssertionFailedError
【发布时间】:2010-09-07 10:53:28
【问题描述】:

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

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

轨迹如下所示:

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'

Shouda 和 Amazon S3 gem 都是最新版本。

任何想法我做错了什么?

【问题讨论】:

    标签: ruby-on-rails testing ruby-on-rails-3 amazon-s3 shoulda


    【解决方案1】:

    这已报告http://github.com/thoughtbot/shoulda/issues/issue/117

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

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

    【讨论】:

    • 哎呀 - 我忘了提及,我把那个 sn-p 放在 test/test_helper.rb
    【解决方案2】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 2015-01-19
      • 2015-10-29
      • 1970-01-01
      相关资源
      最近更新 更多