Object
Rack::MockRequest helps testing your Rack application without actually using HTTP.
After performing a request on a URL with get/post/put/delete, it returns a MockResponse with useful helper methods for effective testing.
You can pass a hash with additional configuration to the get/post/put/delete.
| :input: | A String or IO-like to be used as rack.input. |
| :fatal: | Raise a FatalWarning if the app writes to rack.errors. |
| :lint: | If true, wrap the application in a Rack::Lint. |
Return the Rack environment used for a request to uri.
# File lib/rack/mock.rb, line 74
74: def self.env_for(uri="", opts={})
75: uri = URI(uri)
76: env = DEFAULT_ENV.dup
77:
78: env["REQUEST_METHOD"] = opts[:method] || "GET"
79: env["SERVER_NAME"] = uri.host || "example.org"
80: env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80"
81: env["QUERY_STRING"] = uri.query.to_s
82: env["PATH_INFO"] = (!uri.path || uri.path.empty?) ? "/" : uri.path
83: env["rack.url_scheme"] = uri.scheme || "http"
84:
85: env["SCRIPT_NAME"] = opts[:script_name] || ""
86:
87: if opts[:fatal]
88: env["rack.errors"] = FatalWarner.new
89: else
90: env["rack.errors"] = StringIO.new
91: end
92:
93: opts[:input] ||= ""
94: if String === opts[:input]
95: env["rack.input"] = StringIO.new(opts[:input])
96: else
97: env["rack.input"] = opts[:input]
98: end
99:
100: env["CONTENT_LENGTH"] ||= env["rack.input"].length.to_s
101:
102: opts.each { |field, value|
103: env[field] = value if String === field
104: }
105:
106: env
107: end
(Not documented)
# File lib/rack/mock.rb, line 58
58: def delete(uri, opts={}) request("DELETE", uri, opts) end
(Not documented)
# File lib/rack/mock.rb, line 55
55: def get(uri, opts={}) request("GET", uri, opts) end
(Not documented)
# File lib/rack/mock.rb, line 56
56: def post(uri, opts={}) request("POST", uri, opts) end
(Not documented)
# File lib/rack/mock.rb, line 57
57: def put(uri, opts={}) request("PUT", uri, opts) end
(Not documented)
# File lib/rack/mock.rb, line 60
60: def request(method="GET", uri="", opts={})
61: env = self.class.env_for(uri, opts.merge(:method => method))
62:
63: if opts[:lint]
64: app = Rack::Lint.new(@app)
65: else
66: app = @app
67: end
68:
69: errors = env["rack.errors"]
70: MockResponse.new(*(app.call(env) + [errors]))
71: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.