RSpec Post 带有文件、参数和 header 字段

RSpec Post with a file, params and header field

我正在尝试使用 RSpec 来测试 api 上传文件。 api 请求是一个简单的 POST 请求,其中包含一个文件以及一些参数和一个 header 字段。

我尝试使用以下代码发出 POST 请求:

post "media.upload", { client_id: @client.id, token: @client.token, type: @type, name: @name, format: 'json' },
{ 'HTTP_PROXY_SSL' => 'true' }, :upload => @file

但我收到以下错误:

Failure/Error: post "cm/media.upload", { client_id: @client.id, token: @client.token, type: @type, name: @name, format: 'json' },
     ArgumentError:
       wrong number of arguments (4 for 1..3)

@file变量定义为:

@file = fixture_file_upload(Rails.root + 'spec/fixtures/images/abc.jpg', 'image/jpeg')

所以我的问题是如何在 RSpec 中使用文件、参数和一些 header 执行 POST 请求?

upload 参数与其余请求参数一起移动:

params = {upload: @file, client_id: @client.id, token: @client.token, type: @type, name: @name, format: 'json'}
headers = {'HTTP_PROXY_SSL' => 'true'}

post 'media.upload', params, headers