views:

115

answers:

1

What is the best way for testing file uploads for Rails Applications? I'm currently using Paperclip for uploads, but I guess that doesn't make much difference.

Should I even create tests for file upload, or is it better to just stub it all out and don't create any real upload tests?

Say I have some tests just for the upload. Should I also cover cropping in my tests?

What would be the best way to test image cropping?

+2  A: 

Cucumber with Webrat gives you the step of:

When I attach the file at "spec/fixtures/fugu.png" to "file"

which you can use in features. For more information about the official Cucumber site is very helpful.

Secondly, to test for the cropping you could code a custom step for this:

Then /^the image "(.*?)" should be (\d+)x(\d+)$/ do |id, width, height|
  image = Nokogiri::HTML(response.body).css("##{id}")
  image["width"].should eql(width)
  image["height"].should eql(height)
end
Ryan Bigg