lib/rack/mock.rb in rack-0.1.0 vs lib/rack/mock.rb in rack-0.2.0
- old
+ new
@@ -1,9 +1,10 @@
require 'uri'
require 'stringio'
require 'rack/lint'
require 'rack/utils'
+require 'rack/response'
module Rack
# Rack::MockRequest helps testing your Rack application without
# actually using HTTP.
#
@@ -14,11 +15,11 @@
# You can pass a hash with additional configuration to the
# get/post/put/delete.
# <tt>:input</tt>:: A String or IO-like to be used as rack.input.
# <tt>:fatal</tt>:: Raise a FatalWarning if the app writes to rack.errors.
# <tt>:lint</tt>:: If true, wrap the application in a Rack::Lint.
-
+
class MockRequest
class FatalWarning < RuntimeError
end
class FatalWarner
@@ -30,10 +31,14 @@
raise FatalWarning, warning
end
def flush
end
+
+ def string
+ ""
+ end
end
DEFAULT_ENV = {
"rack.version" => [0,1],
"rack.input" => StringIO.new,
@@ -123,50 +128,18 @@
end
# Status
attr_reader :status
- def invalid?; @status < 100 || @status >= 600; end
-
- def informational?; @status >= 100 && @status < 200; end
- def successful?; @status >= 200 && @status < 300; end
- def redirection?; @status >= 300 && @status < 400; end
- def client_error?; @status >= 400 && @status < 500; end
- def server_error?; @status >= 500 && @status < 600; end
-
- def ok?; @status == 200; end
- def forbidden?; @status == 403; end
- def not_found?; @status == 404; end
-
- def redirect?; [301, 302, 303, 307].include? @status; end
- def empty?; [201, 204, 304].include? @status; end
-
# Headers
attr_reader :headers, :original_headers
- def include?(header)
- !!headers[header]
- end
-
def [](field)
headers[field]
end
- def content_type
- headers["Content-Type"]
- end
- def content_length
- cl = headers["Content-Length"]
- cl ? cl.to_i : cl
- end
-
- def location
- headers["Location"]
- end
-
-
# Body
attr_reader :body
def =~(other)
@body =~ other
@@ -177,7 +150,10 @@
end
# Errors
attr_accessor :errors
+
+
+ include Response::Helpers
end
end