简体   繁体   中英

NameError: uninitialized constant Test::Unit::AssertionFailedError when upgrading to rails3

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM