2011-08-25 35 views
1

我開始爲應用程序編寫測試,並且無法使測試環境正常工作。 我的系統有用於文件上傳的回形針,它試圖啓動服務器甚至初始化新的公司記錄!舉例:測試環境 - 使用回形針的錯誤

# Company.rb line 3 
has_attached_file :photo, 
    :styles => {:medium => "200x300>", :thumb => "100x150>" }, 
    :storage => :s3, 
    :s3_credentials => "#{::Rails.root.to_s}/config/s3.yml", 
    :path => "/photos/:style/:id/:basename.:extension" 

# console 
ruby-1.9.2-p0 :001 > Company.new 
NoMethodError: You have a nil object when you didn't expect it! 
You might have expected an instance of Array. 
The error occurred while evaluating nil.[]= 
from /Users/san/Documents/san/app/vendor/plugins/paperclip/lib/paperclip.rb:232:in 'has_attached_file' 
from /Users/san/Documents/san/app/app/models/company.rb:3:in '<class:company>' 
from /Users/san/Documents/san/app/app/models/company.rb:1:in '<top (required)>' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in 'load' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in 'block in load_file' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in 'new_constants_in' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:453:in 'load_file' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:340:in 'require_or_load' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:491:in 'load_missing_constant' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:183:in 'block in const_missing' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in 'each' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in 'const_missing' 
from /Users/san/.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' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in 'const_missing' 
from (irb):1 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in 'start' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in 'start' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in '<top (required)>' 
from script/rails:6:in 'require' 

你知道是什麼原因導致了這個衝突,我該如何修復它?


我通過回形針文檔閱讀,我發現需要補充:

require 'paperclip/matchers' 
Spec::Runner.configure do |config| 
    config.include Paperclip::Shoulda::Matchers 
end 

spec_helper.rb。仍然得到相同的錯誤!

+0

公司模式的第10行是什麼? –

+0

'has_attached_file:photo'行。 – sscirrus

+0

@RyanBigg - 我正在做更多的挖掘,並意識到它比Rspec更廣泛。當我在我的測試控制檯中運行像Employee.new這樣簡單的操作時,我得到了同樣的錯誤(試圖評估nil。[] ='並指向Employee的第一個附件)。 – sscirrus

回答

0

最後,通過將Paperclip降級到2.3.6,這正是我一直使用到一週前的錯誤。希望這有助於任何人在未來遇到這種錯誤!

0

我想那是什麼s3.yml不包含您當前Rails環境的密鑰,可能是test?加一個。這應該解決它!

+0

我檢查了S3存儲桶名稱,access_key和secret_access_key,並且所有內容似乎都已檢出。它可能是別的嗎? – sscirrus