在运行capybara特性规范时,我可以看到许多由factory_girl填充的缓慢工厂通知。这些慢工厂的东西然后我进行了一些检查,发现大多数缓慢的工厂是由paperclip造成的。我们这里有用回形针的模型:
FactoryGirl.define do
factory :asset do
image Rails.root.join('spec/fixtures/sample.jpg').open
end
end因此,我想知道是否有类似于paperclip的测试模式来加速测试。这里我有一个简单的解决方案:只复制原始文件,而不是实际裁剪它。
发布于 2013-09-05 02:31:52
我找到了实现这一目标的方法,请参见下面的代码:
FactoryGirl.define do
factory :asset do
image_file_name { 'sample.jpg' }
image_content_type 'image/jpeg'
image_file_size 256
after(:create) do |asset|
image_file = Rails.root.join("spec/fixtures/#{asset.image_file_name}")
# cp test image to direcotries
[:original, :medium, :thumb].each do |size|
dest_path = asset.image.path(size)
`mkdir -p #{File.dirname(dest_path)}`
`cp #{image_file} #{dest_path}`
end
end
end
end创建钩子后,将测试映像手动cp到factory_girl中的真实资产映像路径。就像一种魅力。
发布于 2013-09-04 04:41:37
您可以在工厂中设置回形针图像字段,这将导致回形针甚至不试图处理图像:
factory :asset do
# Set the image fields manually to avoid uploading / processing the image
image_file_name { 'test.jpg' }
image_content_type { 'image/jpeg' }
image_file_size { 256 }
endhttps://stackoverflow.com/questions/18605203
复制相似问题