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
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.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/rack/mock.rb', line 142 def initialize(status, headers, body, errors=StringIO.new("")) @status = status.to_i @original_headers = headers @headers = Rack::Utils::HeaderHash.new headers.each { |field, values| @headers[field] = values @headers[field] = "" if values.empty? } @body = "" body.each { |part| @body << part } @errors = errors.string if errors.respond_to?(:string) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Body
170 171 172 |
# File 'lib/rack/mock.rb', line 170 def body @body end |
#errors ⇒ Object
Errors
182 183 184 |
# File 'lib/rack/mock.rb', line 182 def errors @errors end |
#headers ⇒ Object (readonly)
Headers
162 163 164 |
# File 'lib/rack/mock.rb', line 162 def headers @headers end |
#original_headers ⇒ Object (readonly)
Headers
162 163 164 |
# File 'lib/rack/mock.rb', line 162 def original_headers @original_headers end |
#status ⇒ Object (readonly)
Status
159 160 161 |
# File 'lib/rack/mock.rb', line 159 def status @status end |
Instance Method Details
#=~(other) ⇒ Object
172 173 174 |
# File 'lib/rack/mock.rb', line 172 def =~(other) @body =~ other end |
#[](field) ⇒ Object
164 165 166 |
# File 'lib/rack/mock.rb', line 164 def [](field) headers[field] end |
#match(other) ⇒ Object
176 177 178 |
# File 'lib/rack/mock.rb', line 176 def match(other) @body.match other end |