Specifying Content Type in rspec

前端 未结 7 1768
终归单人心
终归单人心 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:52

    A slightly more elegant test is to use the header helper:

    header "HTTP_ACCEPT", "application/json"
    json = {.... data ....}.to_json
    post '/model1.json', json
    

    Now this does exactly the same thing as setting @env; it's just a bit prettier.

提交回复
热议问题