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

标签 ruby-on-rails ruby-on-rails-3 testing rspec paperclip

我正开始为一个应用程序编写测试,但我无法让测试环境正常工作。 我的系统有用于文件上传的 Paperclip,它在任何尝试启动服务器甚至初始化新公司记录时都会出错!一个例子:

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

您知道导致此冲突的原因以及我该如何解决吗?


我通读了 Paperclip 文档,发现需要添加:

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

spec_helper.rb。仍然出现同样的错误!

最佳答案

我想那是什么 s3.yml 不包含当前 Rails 环境的 key ,可能是 test?加一个。这应该可以解决它!

关于ruby-on-rails - 测试环境 - 回形针错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7185493/

相关文章:

testing - 你如何使用 go (golang) gocheck 测试框架的基准标志?

ruby-on-rails - 调用操作后将列更新为 NULL

ruby-on-rails - 如果事件不适用于当前状态(未定义转换),如何告诉 AASM 忽略该事件?

sql - Rails 在 ActiveRecord::Relation 中使用 OR 进行搜索

ruby-on-rails-3 - 轨道 3 Link_to :remote is not triggering RJS

ruby-on-rails - 带 rspec 的 capybara

scala - 如果我有一个 SBT 多项目构建,我怎样才能使 A 的测试依赖项不泄漏到 B 的测试中

ruby-on-rails - Mongoid动态改变主机

ruby-on-rails - 使用嵌套资源测试 Controller

ruby - 如何确定 Rails 3 模型类中的表名