如何将以下 CURL PUT 请求转换为 rspec 并测试 JSON 解析器的行为。
curl -D - -X PUT --data "not json" -H "Content-Type: application/json" http://localhost:3000
以及如何检查响应?提前谢谢你。
请您参考如下方法:
最好是使用vcr gem https://github.com/vcr/vcr
像https://github.com/vcr/vcr#usage一样简单地创建脚本但有适当的 HTTP 请求。
VCR.use_cassette("json_test") do
req = Net::HTTP::Put.new('http://localhost:3000', 'not json')
req.content_type = 'application/json'
res = Net::HTTP.get_response(req)
end
有了这个真正的 HTTP 请求将被记录一次,并且在 rspec 中将使用本地文件。