undefined method `file_fixture_path' after upgrade to ruby 3 and rails 6.1

Ran into the same error, but had to solve it differently as the post in a request spec doesn't accept the object returned by file_fixture.

Including include ActionDispatch::TestProcess::FixtureFile in my request solved it for me.

RSpec.describe "Attachments", type: :request do
  include Rack::Test::Methods
  include ActionDispatch::TestProcess::FixtureFile
  #...
    expect {
      file = fixture_file_upload("image.jpg", "image/jpeg", :binary)
      post collection_work_attachments_path(collection, work), {attachment: {file: file, name: image_name, visibility: [:admin]}}
    }.to change(Attachment, :count).by(1)
  #...
end

Anything above didn't worked for me, but I found another solution.

In the factory changed this:

photo { fixture_file_upload(Rails.root.join('spec/support/images/test_image.png'), 'image/png') }

to this:

photo { Rack::Test::UploadedFile.new('spec/support/images/test_image.png', 'image/png') }

But after that I faced with another error:

unknown attribute 'service_name' for ActiveStorage::Blob

And solved this with two commands:

rails active_storage:update
rails db:migrate

I hope this may be useful to anybody.


Adding the following initializer addresses the issue without potential side-effects of including the ActionDispatch::TestProcess::FixtureFile module.

# config/initializers/rspec.rb

module RSpec
  module Rails
    module FixtureFileUploadSupport
      class RailsFixtureFileWrapper
        class << self
          attr_accessor :file_fixture_path
        end
      end
    end
  end
end

This is how the issue is actually fixed by RSpec maintainers. As of the date of this post, the patch is not yet released.