Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 24 lines (23 sloc) 0.723 kB
b457d38 @bblimke Added minitest spec to ensure webmock works with Minitest::Spec. Unfo…
authored
1 require 'ostruct'
2
3 module HttpRequestTestHelper
4 def http_request(method, uri, options = {})
5 begin
6 uri = URI.parse(uri)
7 rescue
8 uri = Addressable::URI.heuristic_parse(uri)
9 end
10 response = nil
11 clazz = ::Net::HTTP.const_get("#{method.to_s.capitalize}")
12 req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", options[:headers])
13 req.basic_auth uri.user, uri.password if uri.user
14 http = ::Net::HTTP.new(uri.host, uri.port)
15 http.use_ssl = true if uri.scheme == "https"
16 response = http.start {|http|
17 http.request(req, options[:body])
18 }
19 OpenStruct.new({
20 :body => response.body,
21 :headers => response,
22 :status => response.code })
23 end
24 end
Something went wrong with that request. Please try again.