test a file upload using rspec - rails

后端 未结 6 2081
梦毁少年i
梦毁少年i 2020-11-27 09:52

I want to test a file upload in rails, but am not sure how to do this.

Here is the controller code:

def uploadLicense
    #Create the license object
         


        
6条回答
  •  隐瞒了意图╮
    2020-11-27 10:50

    if you include Rack::Test*, simply include the test methods

    describe "my test set" do
      include Rack::Test::Methods
    

    then you can use the UploadedFile method:

    post "/upload/", "file" => Rack::Test::UploadedFile.new("path/to/file.ext", "mime/type")
    

    *NOTE: My example is based on Sinatra, which extends Rack, but should work with Rails, which also uses Rack, TTBOMK

提交回复
热议问题