5

RailsアプリケーションをRails3にアップグレードしようとしています。

機能テストを実行すると、多くのNameError: uninitialized constant Test::Unit::AssertionFailedErrorエラーが発生します。しかし、単体テストとWebサイト自体は正常に機能しているようです。

トレースは次のようになります。

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'

ショルダーとアマゾンS3の両方の宝石は最新バージョンです。

私が間違っていることについて何か考えはありますか?

4

2 に答える 2

6

これはhttp://github.com/thoughtbot/shoulda/issues/issue/117で報告されています。

回避策(少なくともこのエラーが解消され、実際に正しく機能するかどうかはわかりません)は次のとおりです。

unless defined?(Test::Unit::AssertionFailedError)
  class Test::Unit::AssertionFailedError < ActiveSupport::TestCase::Assertion
  end
end
于 2010-09-20T17:15:28.123 に答える
6

Ash Berlinのソリューションは例外をなくしますが、それはすべてのマッチャーをtry失敗さcatch Test::Unit::AssertionFailedErrorせます。AssertionFailedErrorがでActiveSupport::TestCase::Assertion、を投げた場合、ActiveSupport::TestCase::AssertionそれをとしてキャッチすることはできませんTest::Unit::AssertionFailedError。彼は相続関係を逆に持っています。代わりに、これをあなたのtest_helper.rb:に入れてください

unless defined?(Test::Unit::AssertionFailedError)
  Test::Unit::AssertionFailedError = ActiveSupport::TestCase::Assertion
end
于 2011-11-16T21:09:17.700 に答える