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

Man*_*tas 5 testing ruby-on-rails shoulda amazon-s3 ruby-on-rails-3

我正在尝试将我的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'
Run Code Online (Sandbox Code Playgroud)

Shoulda和Amazon S3宝石都是最新版本.

我有什么想法我做错了吗?

Ash*_*lor 6

据报道http://github.com/thoughtbot/shoulda/issues/issue/117.

解决方法(至少使这个错误消失,不确定它是否真的正常)是:

unless defined?(Test::Unit::AssertionFailedError)
  class Test::Unit::AssertionFailedError < ActiveSupport::TestCase::Assertion
  end
end
Run Code Online (Sandbox Code Playgroud)


小智 6

灰柏林的解决方案将使异常消失,但它将使任何的匹配是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
Run Code Online (Sandbox Code Playgroud)