Mocking file uploads in Rails 3.1 controller tests

前端 未结 3 1570
一个人的身影
一个人的身影 2021-02-15 04:08

My controller accesses the tempfile attribute of an uploaded file and passes it to another mocked component. My test code has

  @file = mock(Object)         


        
3条回答
  •  不知归路
    2021-02-15 04:56

    I went around this way

    upload_file = fixture_file_upload('files/stats_upload.csv', 'text/csv')
    upload_file.stubs(:tempfile).returns(upload_file)
    

提交回复
热议问题