httpx/standalone_tests/response_json_multi_json_test.rb
HoneyryderChuck 8b2ee0b466 remove form, json, ,xml and body from the Options class
Options become a bunch of session and connection level parameters, and requests do not need to maintain a separate Options object when they contain a body anymore, instead, objects is shared with the session, while request-only parameters get passed downwards to the request and its body. This reduces allocations of Options, currently the heaviest object to manage.
2024-06-11 18:23:45 +01:00

28 lines
678 B
Ruby

# frozen_string_literal: true
require "multi_json"
require "test_helper"
class ResponseYajlTest < Minitest::Test
include HTTPX
def test_response_decoders
json_response = Response.new(request, 200, "2.0", { "content-type" => "application/json" })
json_response << %({"a": "b"})
assert json_response.json == { "a" => "b" }
assert json_response.json(symbolize_keys: true) == { :a => "b" }
json_response << "bogus"
assert_raises(MultiJson::ParseError) { json_response.json }
end
private
def request(verb = "GET", uri = "http://google.com")
Request.new(verb, uri, Options.new)
end
def response(*args)
Response.new(*args)
end
end