thoughtbot/paperclip — Issue #646: ValidateAttachmentSizeMatcher attempts to post_process a StringIO
Author: mattvanhorn
Created: 2011-11-20 02:25:36+00:00
State: open

Trying to use paperclip 2.4.5 matchers with RSpec 2.7.0

```ruby
class Widget < ActiveRecord::Base
validates_attachment_size :photo, :less_than => 2.megabytes
has_attached_file :photo, :styles => { :large => "300x400>" }
end
```

When I try

```ruby
it { should validate_attachment_size(:photo).less_than(2.megabytes) }
```
I get a lot of noise from ImageMagick identify. This is because it is trying to generate a thumbnail for the StringIO the matchers use in place of a file, for testing.

I am working around it by doing this:

```ruby
it "validates the photo file size" do
@it = Widget.new
@it.stub!(:before_post_process => false)
@it.should validate_attachment_size(:photo).less_than(2.megabytes)
end
```

It works for me for now, but I'm wondering if that shouldn't be folded into the matcher itself, somehow. Post processing in validate_attachment_content_type slows down the tests quite a bit, because it is writing to tmp files on disk.

If it's not a bug, then at least this issue + google can save the next person the time it took me to track down the source of the errors and slowness.