Class: Rack::MockResponse
Overview
Rack::MockResponse provides useful helpers for testing your apps. Usually, you don't create the MockResponse on your own, but use MockRequest.
Constant Summary
Constants inherited from Response
Response::CHUNKED, Response::STATUS_WITH_NO_ENTITY_BODY
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Headers.
-
#errors ⇒ Object
Errors.
-
#original_headers ⇒ Object
readonly
Headers.
Attributes inherited from Response
Instance Method Summary collapse
- #=~(other) ⇒ Object
- #body ⇒ Object
- #cookie(name) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(status, headers, body, errors = StringIO.new("")) ⇒ MockResponse
constructor
A new instance of MockResponse.
- #match(other) ⇒ Object
Methods inherited from Response
#chunked?, #close, #delete_header, #each, #finish, #get_header, #has_header?, #redirect, #set_header, #write
Methods included from Response::Helpers
#accepted?, #add_header, #bad_request?, #cache!, #cache_control, #cache_control=, #client_error?, #content_length, #content_type, #content_type=, #created?, #delete_cookie, #do_not_cache!, #etag, #etag=, #forbidden?, #include?, #informational?, #invalid?, #location, #location=, #media_type, #media_type_params, #method_not_allowed?, #moved_permanently?, #no_content?, #not_found?, #ok?, #precondition_failed?, #redirect?, #redirection?, #server_error?, #set_cookie, #set_cookie_header, #set_cookie_header=, #successful?, #unauthorized?, #unprocessable?
Constructor Details
#initialize(status, headers, body, errors = StringIO.new("")) ⇒ MockResponse
Returns a new instance of MockResponse.
184 185 186 187 188 189 190 191 192 |
# File 'lib/rack/mock.rb', line 184 def initialize(status, headers, body, errors = StringIO.new("")) @original_headers = headers @errors = errors.string if errors.respond_to?(:string) @cookies = super(body, status, headers) buffered_body! end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Headers
179 180 181 |
# File 'lib/rack/mock.rb', line 179 def @cookies end |
#errors ⇒ Object
Errors
182 183 184 |
# File 'lib/rack/mock.rb', line 182 def errors @errors end |
#original_headers ⇒ Object (readonly)
Headers
179 180 181 |
# File 'lib/rack/mock.rb', line 179 def original_headers @original_headers end |
Instance Method Details
#=~(other) ⇒ Object
194 195 196 |
# File 'lib/rack/mock.rb', line 194 def =~(other) body =~ other end |
#body ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/rack/mock.rb', line 202 def body # FIXME: apparently users of MockResponse expect the return value of # MockResponse#body to be a string. However, the real response object # returns the body as a list. # # See spec_showstatus.rb: # # should "not replace existing messages" do # ... # res.body.should == "foo!" # end buffer = String.new super.each do |chunk| buffer << chunk end return buffer end |
#cookie(name) ⇒ Object
226 227 228 |
# File 'lib/rack/mock.rb', line 226 def (name) .fetch(name, nil) end |
#empty? ⇒ Boolean
222 223 224 |
# File 'lib/rack/mock.rb', line 222 def empty? [201, 204, 304].include? status end |
#match(other) ⇒ Object
198 199 200 |
# File 'lib/rack/mock.rb', line 198 def match(other) body.match other end |