Testing an Uploaded Image With RSpec

July 17th, 2016

I had some initial difficulty testing my photos controller with an uploaded file for the :image field, because the test was reading :image as nil. What worked was wrapping the image in a content wrapper using Class: Rack::Test::UploadedFile. I have this implemented in my factory: image { Rack::Test::UploadedFile.new(File.open(File.join(Rails.root, ‘/spec/support/my_image.jpg’)), ‘image/jpeg’) } The image file “my_image.jpg” […]