fixture_file_upload has {file} does not exist error

前端 未结 3 1272
误落风尘
误落风尘 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:23

    Fixture_file_upload basically still works. You just need to make sure the fixtures path in your spec_helper.rb file is uncommented & correctly set to the spec/fixtures path & to include ActionDispath::TestProcess:

    RSpec.configure do |config|
      config.include ActionDispatch::TestProcess
    
      # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
      config.fixture_path = "#{::Rails.root}/spec/fixtures"
    
      ...
    

    And where you are specifying the file in your tests, be sure to precede your file name with '/' like the following example:

    describe "POST /subscriber_imports" do
      let(:file) { { :file => fixture_file_upload('/files/data.csv', 'text/csv') } }
      subject { post :create, :subscriber_import => file }
      ...
    end
    

    The absolute path to the file is the base path specified in config.fixture_path plus the relative path specified in fixture_file_upload function call. So, in this example, file.csv must be placed in #{::Rails.root}/spec/fixtures/files/data.csv

提交回复
热议问题