繁体   English   中英

如何加快涉及图像上传/调整大小的Rails单元测试?

[英]How can I speed up Rails unit tests involving image upload/resizing?

我的应用程序对图像做了很多。 我用回形针将它们附加到模型上。 我有很多涉及创建图像的测试(Test :: Unit),这些测试运行起来非常慢。

我使用FactoryGirl在我的测试中创建模型。 这就是我创建图像附件的方式:

factory :product_image_100_100 do
    image File.new(File.join(::Rails.root.to_s, "/test/fixtures/images", "100_100.jpg"))
end

如何伪造图片上传或以其他方式加快速度?

这个片段对我有用

require 'test_helper'
class PhotoTest < ActiveSupport::TestCase
  setup do
    Paperclip::Attachment.any_instance.stubs(:post_process).returns(true)
  end

  # tests...
end

UPD。 我目前的偏好是通过在test_helper.rb中添加以下内容来全局存取ImageMagic:

module Paperclip
 def self.run(cmd, *)
   case cmd
   when "identify"
     return "100x100"
   when "convert"
     return
   else
     super
   end
 end
end

(改编自这里 - 顺便说一句,如果你对加速测试感兴趣,你可能想看看这篇文章)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM