fixture_file_upload has {file} does not exist error

前端 未结 3 1271
误落风尘
误落风尘 2021-02-05 08:42

Below is my testing code for uploading file.

describe \"file process\" do
 before(:each) do
   # debugger
   @file = fixture_file_upload(\'test.csv\', \'text/csv         


        
3条回答
  •  囚心锁ツ
    2021-02-05 09:02

    This is how I did it with Rails 6, RSpec and Rack::Test::UploadedFile

    describe 'POST /create' do
      it 'responds with success' do
        post :create, params: {
          company: {
            logo: Rack::Test::UploadedFile.new("#{Rails.root}/spec/fixtures/test-pic.png"),
            name: 'test'
          }
        }
    
        expect(response).to be_successful
      end
    end
    

    DO NOT include ActionDispatch::TestProcess or any other code unless you're sure about what you're including.

提交回复
热议问题