2
我想测试一个多/形式与后RSPEC用下面的代码:如何测试多用后RSPEC
@req = { :post => @attr }
lambda {
post :create, :POSTDATA => @req, :format => :json
}.should change(Post, :count).by(1)
,但我得到了以下错误:
undefined method `stringify_keys' for "post":String
POSTDATA是多部分表单名称。
什么是测试多部分请求的正确方法?
编辑:
我想通了,建设的要求就像我在上面做只是建立了一个嵌套的JSON请求。我该如何构建一个multipost/form请求?
我想建立一个看起来像multipart请求:
POST /api/posts.json HTTP/1.1
Accepts: application/json
X-API-KEY: 7d867d16a5e25337b6d7857965f812bee73b76ac
Content-Length: 288
Content-Type: multipart/form-data; boundary=syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS
Host: 10.0.2.2:3000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
--syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS
Content-Disposition: form-data; name="POSTDATA"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
{"tags":["dffdff"],"location_id":3,"post":{"content":"test #dffdff"}}
--syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS--
看看http://stackoverflow.com/questions/7260394/test-a-file-upload-using-rspec-rails – Vik 2012-04-10 07:43:58
我似乎没有找到相关的答案。我不想测试文件的上传 – 2012-04-10 09:10:23
Vik,请你指点一下我在那个链接上寻找什么? – 2012-04-14 09:04:38