lib/rack/mock.rb in rack-1.5.5 vs lib/rack/mock.rb in rack-1.6.0.beta
- old
+ new
@@ -51,16 +51,17 @@
def initialize(app)
@app = app
end
- def get(uri, opts={}) request("GET", uri, opts) end
- def post(uri, opts={}) request("POST", uri, opts) end
- def put(uri, opts={}) request("PUT", uri, opts) end
- def patch(uri, opts={}) request("PATCH", uri, opts) end
- def delete(uri, opts={}) request("DELETE", uri, opts) end
- def head(uri, opts={}) request("HEAD", uri, opts) end
+ def get(uri, opts={}) request("GET", uri, opts) end
+ def post(uri, opts={}) request("POST", uri, opts) end
+ def put(uri, opts={}) request("PUT", uri, opts) end
+ def patch(uri, opts={}) request("PATCH", uri, opts) end
+ def delete(uri, opts={}) request("DELETE", uri, opts) end
+ def head(uri, opts={}) request("HEAD", uri, opts) end
+ def options(uri, opts={}) request("OPTIONS", uri, opts) end
def request(method="GET", uri="", opts={})
env = self.class.env_for(uri, opts.merge(:method => method))
if opts[:lint]
@@ -74,12 +75,19 @@
MockResponse.new(status, headers, body, errors)
ensure
body.close if body.respond_to?(:close)
end
+ # For historical reasons, we're pinning to RFC 2396. It's easier for users
+ # and we get support from ruby 1.8 to 2.2 using this method.
+ def self.parse_uri_rfc2396(uri)
+ @parser ||= defined?(URI::RFC2396_Parser) ? URI::RFC2396_Parser.new : URI
+ @parser.parse(uri)
+ end
+
# Return the Rack environment used for a request to +uri+.
def self.env_for(uri="", opts={})
- uri = URI(uri)
+ uri = parse_uri_rfc2396(uri)
uri.path = "/#{uri.path}" unless uri.path[0] == ?/
env = DEFAULT_ENV.dup
env["REQUEST_METHOD"] = opts[:method] ? opts[:method].to_s.upcase : "GET"