Paperclip/Rspec测试:有没有更快的方法来测试paperclip validates_attachment_content_type?

Pla*_*Ton 11 rspec ruby-on-rails shoulda paperclip paperclip-validation

我注意到的一件事是,在我做的大多数项目中,一个需要很长时间(30秒+)的规范就是这个应该/回形针助手:

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

我非常想保留内容类型验证,但我想知道是否有更快的方法来实现它.我已经用以下标记标记了这些测试:慢速运行rspec而没有:慢速规范,但是,我希望有人能够更快地测试图像内容类型.

Kev*_*vin 0

看起来您正在针对回形针运行自己的测试。

一般来说,我会让 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
Run Code Online (Sandbox Code Playgroud)