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