Verifying file downloads using rspec

How can I create a test file with a given size and upload a test file to rspec? I want to generate a file.

I currently have files in files / files and use the fixture_file_upload file as a test file. I want to eliminate the need for this sample file.

+4
source share
2 answers

You can use factory_girl or fabrication to make fun of the downloaded file.

An example configuration for factory_girlwould look like this:

factory :attachment do
  supporting_documentation_file_name { 'test.pdf' }
  supporting_documentation_content_type { 'application/pdf' }
  supporting_documentation_file_size { 1024 }
end

, factory girl

, , . , ( , , ), .

Mocking Rails 3.1

+3

- , :

    file = Rack::Test::UploadedFile.new(File.join(Rails.root, 'app', 'assets', 'images', 'test-file.jpg'), 'image/jpg')

    allow_any_instance_of(Model).to receive(:photo_obj).and_return file
0

Source: https://habr.com/ru/post/1541074/


All Articles