1

I am using RSpec (Rails 3.2) to test my controllers. I have a controller which also contains a fileupload (using CarrierWave), but I keep getting the error:

Failure/Error: "image" => fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'image.png'), 'image/png') RuntimeError: .../spec/fixtures/files/image.png file does not exist

In my controller I have defined the image upload like this:

  def valid_attributes
{ "title" => "My own title",
  "description" => "Something cool",
  "image" => fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'image.png'), 'image/png')
}

end

I have of course checked that file exists, but might there be something else that I have overlooked?

Dofs
  • 17,737
  • 28
  • 75
  • 123

1 Answers1

4

Seems you have to use Rack::Test::UploadedFile.new rather than fixture_file_upload in Rails 3.2:

def valid_attributes
  { "title" => "My own title",
    "description" => "Something cool",
    "image" => Rack::Test::UploadedFile.new(Rails.root.join('spec', 'fixtures', 'files', 'image.png'), 'image/png')
  }
end

See this SO question/answers: fixture_file_upload has {file} does not exist error

Community
  • 1
  • 1
Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82