Class: Rack::MockResponse
- Inherits:
-
Object
- Object
- Rack::MockResponse
- Includes:
- Response::Helpers
- Defined in:
- lib/rack/mock.rb
Overview
Rack::MockResponse provides useful helpers for testing your apps. Usually, you don’t create the MockResponse on your own, but use MockRequest.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Body.
-
#errors ⇒ Object
Errors.
-
#headers ⇒ Object
readonly
Headers.
-
#original_headers ⇒ Object
readonly
Headers.
-
#status ⇒ Object
readonly
Status.
Instance Method Summary collapse
- #=~(other) ⇒ Object
- #[](field) ⇒ Object
-
#initialize(status, headers, body, errors = StringIO.new("")) ⇒ MockResponse
constructor
A new instance of MockResponse.
- #match(other) ⇒ Object
-
#send_header(*args) ⇒ Object
Included for compatibility with MongrelHandler.
-
#send_status_no_connection_close(*args) ⇒ Object
Included for compatibility with MongrelHandler.
Methods included from Response::Helpers
#client_error?, #content_length, #content_type, #empty?, #forbidden?, #include?, #informational?, #invalid?, #location, #not_found?, #ok?, #redirect?, #redirection?, #server_error?, #successful?
Constructor Details
#initialize(status, headers, body, errors = StringIO.new("")) ⇒ MockResponse
Returns a new instance of MockResponse.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rack/mock.rb', line 113 def initialize(status, headers, body, errors=StringIO.new("")) @status = status.to_i @original_headers = headers @headers = Rack::Utils::HeaderHash.new headers.each { |field, values| values.each { |value| @headers[field] = value } @headers[field] = "" if values.empty? } @body = "" if body.respond_to?(:call) body.call(self) else body.each { |part| @body << part } end @errors = errors.string end |
Instance Attribute Details
#body ⇒ Object (readonly)
Body
155 156 157 |
# File 'lib/rack/mock.rb', line 155 def body @body end |
#errors ⇒ Object
Errors
167 168 169 |
# File 'lib/rack/mock.rb', line 167 def errors @errors end |
#headers ⇒ Object (readonly)
Headers
144 145 146 |
# File 'lib/rack/mock.rb', line 144 def headers @headers end |
#original_headers ⇒ Object (readonly)
Headers
144 145 146 |
# File 'lib/rack/mock.rb', line 144 def original_headers @original_headers end |
#status ⇒ Object (readonly)
Status
137 138 139 |
# File 'lib/rack/mock.rb', line 137 def status @status end |
Instance Method Details
#=~(other) ⇒ Object
157 158 159 |
# File 'lib/rack/mock.rb', line 157 def =~(other) @body =~ other end |
#[](field) ⇒ Object
146 147 148 |
# File 'lib/rack/mock.rb', line 146 def [](field) headers[field] end |
#match(other) ⇒ Object
161 162 163 |
# File 'lib/rack/mock.rb', line 161 def match(other) @body.match other end |
#send_header(*args) ⇒ Object
Included for compatibility with MongrelHandler
151 152 |
# File 'lib/rack/mock.rb', line 151 def send_header(*args) end |
#send_status_no_connection_close(*args) ⇒ Object
Included for compatibility with MongrelHandler
140 141 |
# File 'lib/rack/mock.rb', line 140 def send_status_no_connection_close(*args) end |