13

One thing I've noticed is that in most of the projects I do, the one spec that always takes a long time (30 seconds +) is this shoulda/paperclip helper:

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

I'd quite like to keep content type validation in, but I'm wondering if there's a speedier way to do it. I already tag these tests with a :slow and run rspec without :slow specs, but nonetheless, I'm hoping someone has a swifter way of testing image content types.

PlankTon
  • 12,443
  • 16
  • 84
  • 153
  • This spec should run fast since this matcher does not perform any real image upload/writing stuff, check https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb I think the problem might be buried somewhere little deeper. Could you paste the whole spec or `log/test.log` output? – luacassus Oct 24 '12 at 19:49
  • Strangely enough - it does. These days, these sortsa tests typically run in < 0.5s. ...I wish I could help out, but the reference to wherever I was having this issue is long since forgotten – PlankTon Oct 25 '12 at 00:47
  • 1
    I was the one who started the bounty. Using Paperclip 2.x is still very slow. Is this solved in 3.x? – Pedro Nascimento Oct 26 '12 at 19:00
  • My memories of solving this are a little hazy, but I think 3.0 upgrade may have done the trick. Certainly my 3.0 projects don't have this issue. – PlankTon Oct 26 '12 at 19:06

1 Answers1

0

Looks like you're running your own tests against paperclip.

Generally I let gem providers (especially for large products like this one) certify that their specs will run successfully before pushing a release.

I stub out actual paperclip stuff from my tests to make them faster like this, placed in 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
Kevin
  • 4,225
  • 2
  • 37
  • 40
  • That's because you're not stubbing it out correctly. As of today, the correct way to stub it would be: https://gist.github.com/gabrielecirulli/6340651 (it might change in the future due to changes in the code structure of paperclip) – kettlepot Aug 26 '13 at 11:48