2010-09-06 86 views
0

我在Ruby 1.8.7-p174上運行Rails 3.0.0應用程序。一切都進行得順順當當,直到我試圖運行一些測試:在Ruby 1.8.7/1.9.2上的Rails 3中對類'Date'未定義的方法'>>'

/Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:9: undefined method `>>' for class `Date' (NameError) 
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `require' 
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12 
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/actionpack-3.0.0/lib/abstract_controller.rb:6:in `require' 
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/actionpack-3.0.0/lib/abstract_controller.rb:6 

我接過來一看成計算類,並指出undef正在調用:>>。但Ruby 1.8.7 Date s沒有>>方法。我想我會用條件包裝它:if respond_to?(:>>)。事情沿着這個時間進一步突破:

/Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:91:in `alias_method': undefined method `+' for class `Date' (NameError) 
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:91:in `<class:Date>' 
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:7:in `<top (required)>' 
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `require' 
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `<top (required)>' 
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/actionpack-3.0.0/lib/abstract_controller.rb:6:in `require' 

第二個堆棧跟蹤是Ruby 1.9.2。如果沒有將我的respond_to?檢查爲Ruby 1.8.7,我得到了與Ruby 1.9.2相同的錯誤。

我在lib中註釋了我的Date擴展。這隻發生在測試環境中。

想法?

回答

1

所以這可能不是最有用的答案,但這是我迄今爲止所能確定的。

有問題的文件:activesupport-3.0.0/lib/active_support/core_ext/date/computation.rb刪除了>> >>的定義,如您所見。如果該文件需要兩次,則該文件的第二次加載將失敗,因爲該方法不再在Date類中定義。

那麼爲什麼這個文件需要兩次?我真的不確定。我已經看到,當你用完整路徑指定文件一次,然後再一次依賴LOAD_PATH時,防止出現這種情況可能會有問題(如果你稱它爲錯誤,那可能只是一種限制)正確的文件夾中找到你的文件。

我會查看你的代碼,看看有什麼需要rails/all或activesupprt/railstie,希望你會看到兩個看起來稍有不同的地方。另外看看你是否在兩地之間的任何地方使用LOAD_PATH。

相關問題