Specifying Content Type in rspec

前端 未结 7 1772
终归单人心
终归单人心 2021-01-01 12:57

I\'m trying to build an rspec test that sends JSON (or XML) via POST. However, I can\'t seem to actually get it working:

    json = {.... data ....}.to_json
         


        
7条回答
  •  感动是毒
    2021-01-01 13:38

    A lot of frustration and variations and that's what worked for me. Rails 3.2.12 Rspec 2.10

     @request.env["HTTP_ACCEPT"] = "application/json"
     @request.env["CONTENT_TYPE"] = "application/json"
     put :update, :id => 1, "email" => "bing@test.com"
    

提交回复
热议问题