Verifying image file size verification using rspec without using a large file in fixtures

I am using paperclip in rails 3 and I want my application to not allow the user to upload large images.

I can check the presence of the file and the mime type of the image using a tool like this:

it "is not valid without an image" do @post.image = nil @post.should_not be_valid end it "is not valid with the wrong file extension" do @post.image = File.new(Rails.root + 'spec/fixtures/images/rails.bmp') @post.should_not be_valid end 

These tests work just fine. But I do not want to use a large binary for testing. I do not want to have a 6Mb file in my code base for testing.

How can I somehow simulate an image or create an image file during a test, and not use the device? Should I even test this?

Thank you very much...

+4
source share
1 answer

You can use imagemagick if it is installed

 `convert -size 1x1 xc:white empty.jpg` 

will create an empty 1x1 space.

0
source

All Articles