【问题标题】:FactoryGirl and PaperCip attachement工厂女孩和回形针附件
【发布时间】:2013-09-12 13:44:30
【问题描述】:

我有一个模型:

FactoryGirl.define do
  factory :model do
    mini_image { fixture_file_upload(Rails.root.join('spec', 'photos', 'rails.png'), 'image/png') }
    name "Test model"
  end
end

运行 rake 规范时,我收到此错误:

NoMethodError:
   undefined method `fixture_file_upload'

我已经在我的 spec_helper 中添加了这个

config.include ActionDispatch::TestProcess

我发现让我的工厂工作的唯一方法是在我的 models.rb 文件的开头添加这一行,但它不是很干净:

include ActionDispatch::TestProcess

有人有其他解决方案吗?

谢谢

【问题讨论】:

标签: ruby-on-rails ruby rspec paperclip factory-bot


【解决方案1】:

尝试将其添加到您的 spec_helper.rb 中,在 RSpec.configure 块之外。

FactoryGirl::SyntaxRunner.class_eval do
  include ActionDispatch::TestProcess
end

【讨论】:

  • 如果你不使用 RSpec,也可以到 test_helper.rb。
  • 我首先认为这也是我设置的解决方案(Rails 4.2.5、RSpec 3.1.0、FactoryGirl 4.4.0)。然而,不知何故,在退出 Guard(它位于后台)并在命令行上运行 rspec 后,它在我的 spec_helper.rb 文件中的这些行上崩溃了。一个非常简单的解决方案是简单地将include ActionDispatch::TestProcess 放在我使用fixture_file_upload 的工厂文件中(幸运的是只有一个工厂)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多