def build_net_http_response(webmock_response, &block)
response = Net::HTTPResponse.send(:response_class, webmock_response.status[0].to_s).new("1.0", webmock_response.status[0].to_s, webmock_response.status[1])
response.instance_variable_set(:@body, webmock_response.body)
webmock_response.headers.to_a.each do |name, values|
values = [values] unless values.is_a?(Array)
values.each do |value|
response.add_field(name, value)
end
end
response.instance_variable_set(:@read, true)
response.extend Net::WebMockHTTPResponse
raise Timeout::Error, "execution expired" if webmock_response.should_timeout
webmock_response.raise_error_if_any
yield response if block_given?
response
end