回形针/Rspec测试:是否有更快的方法来测试回形针validates_attachment_content_type



我注意到的一件事是,在我做的大多数项目中,一个总是花费很长时间(30秒+)的规范是这个shoulda/回形针帮助器:

it { should validate_attachment_content_type(:bannerimage)
  .allowing('image/png', 'image/jpeg', 'image/gif', 'image/jpg')
  .rejecting('text/plain')
}

我很想保持内容类型验证,但我想知道是否有更快的方法来做到这一点。我已经用:slow标记这些测试,运行rspec没有:slow规格,但尽管如此,我希望有人有一个更快的方法来测试图像内容类型。

看起来你在用回形针做你自己的测试。

一般来说,我让gem提供商(特别是像这样的大型产品)在发布之前证明他们的规范将成功运行。

我从我的测试中去掉了实际的回形针,这样可以使它们更快,放在spec_helper.rb

# stub out paperclip? http://pivotallabs.com/stubbing-out-paperclip-imagemagick-in-tests/
# only like .1 seconds faster anyways though...
module Paperclip
  def self.run cmd, params = "", expected_outcodes = 0
    case cmd
    when "identify"
      return "100x100"
    when "convert"
      return
    else
      super
    end
  end
end
class Paperclip::Attachment
  def post_process
  end
end

最新更新