2010-09-07 78 views
5

我試圖將我的Rails應用程序升級到Rails3。NameError:升級到rails3時,未初始化的常量Test :: Unit :: AssertionFailedError

當我運行功能測試時,出現很多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' 

兩個早該和Amazon S3寶石是最新版本。

任何想法我做錯了什麼?

回答

6

已有報道http://github.com/thoughtbot/shoulda/issues/issue/117

周圍的工作(至少使這個錯誤消失,不知道這是否實際上作品右)是:

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

Ooops - 我忘記了,我把這個片段放在test/test_helper.rb – 2010-09-20 17:15:57

6

灰柏林的解決方案將使異常消失,但它將使任何匹配器trycatchTest::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 
相關問題