Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 测试环境-回形针错误_Ruby On Rails_Ruby On Rails 3_Testing_Rspec_Paperclip - Fatal编程技术网

Ruby on rails 测试环境-回形针错误

Ruby on rails 测试环境-回形针错误,ruby-on-rails,ruby-on-rails-3,testing,rspec,paperclip,Ruby On Rails,Ruby On Rails 3,Testing,Rspec,Paperclip,我开始为一个应用程序编写测试,但在让测试环境正常工作时遇到了问题。 我的系统有用于上传文件的回形针,它在任何试图启动服务器甚至初始化新公司记录时都会出错!例如: # Company.rb line 3 has_attached_file :photo, :styles => {:medium => "200x300>", :thumb => "100x150>" }, :storage => :s3, :s3_credentials =

我开始为一个应用程序编写测试,但在让测试环境正常工作时遇到了问题。 我的系统有用于上传文件的回形针,它在任何试图启动服务器甚至初始化新公司记录时都会出错!例如:

# 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'

spec\u helper.rb
。仍然得到相同的错误

我想这就是s3。yml不包含当前Rails环境的密钥,可能是
test
?加一个。那应该可以解决它

最后,通过将回形针降级到2.3.6,纠正了错误,这是我一周前一直在使用的回形针。希望这对将来遇到此错误的任何人都有帮助

公司模型的第10行是什么?
附有文件:photo
行。@RyanBigg-我正在做更多的挖掘,并意识到它比Rspec更广泛。当我在测试控制台中运行像
Employee.new
这样简单的东西时,我得到了相同的错误(
尝试计算nil.[]=
并指向员工的第一个附件)。我检查了S3存储桶名称、访问密钥和机密访问密钥,似乎一切都正常。可能是别的什么吗?
require 'paperclip/matchers'
Spec::Runner.configure do |config|
  config.include Paperclip::Shoulda::Matchers
end