Errno::ENOENT: No such file or directory @ rb_file_s_mtime after feature tests

后端 未结 3 1185
轻奢々
轻奢々 2020-12-06 07:17

When running feature Rspecs, I receive the following error (full trace at the bottom of this message)

Puma output

Rack app error handling request {         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 07:49

    Something is likely off with how you're setting up the image that you're testing against. You might want to update that to how the Rails team handles it in their own tests:

    module ActiveStorageHelpers
      # ported from https://github.com/rails/rails/blob/5-2-stable/activestorage/test/test_helper.rb#L57
      def create_file_blob(filename: "image.jpg", content_type: "image/jpeg", metadata: nil)
        ActiveStorage::Blob.create_after_upload! io: file_fixture(filename).open, filename: filename, content_type: content_type, metadata: metadata
      end
    end
    
    RSpec.configure do |config|
      config.include ActiveStorageHelpers
    end
    

    Then place a tiny image file in spec/fixtures/file/images.jpg (that's where the file_fixture method will look for it).

    With that in place, you can setup the image on your model in your feature test with something like:

    instance_of_model.images.attach(create_file_blob)
    

提交回复
热议问题