【发布时间】:2015-10-06 12:35:39
【问题描述】:
我正在尝试使用 RSpec 来测试一个用于上传文件的 api。 api 请求是一个简单的 POST 请求,其中包含一个文件以及一些参数和一个标头字段。
我尝试使用以下代码发出 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 中使用文件、参数和一些标头进行 POST 请求?
【问题讨论】:
标签: ruby-on-rails ruby rspec bdd rspec-rails