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_control, #cache_control=, #client_error?, #content_length, #content_type, #created?, #delete_cookie, #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
166 167 168 169 170 171 172 |
# File 'lib/rack/mock.rb', line 166 def initialize(status, headers, body, errors = StringIO.new("")) @original_headers = headers @errors = errors.string if errors.respond_to?(:string) @cookies = super(body, status, headers) end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Headers
161 162 163 |
# File 'lib/rack/mock.rb', line 161 def @cookies end |
#errors ⇒ Object
Errors
164 165 166 |
# File 'lib/rack/mock.rb', line 164 def errors @errors end |
#original_headers ⇒ Object (readonly)
Headers
161 162 163 |
# File 'lib/rack/mock.rb', line 161 def original_headers @original_headers end |
Instance Method Details
#=~(other) ⇒ Object
174 175 176 |
# File 'lib/rack/mock.rb', line 174 def =~(other) body =~ other end |
#body ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/rack/mock.rb', line 182 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 super.join end |
#cookie(name) ⇒ Object
200 201 202 |
# File 'lib/rack/mock.rb', line 200 def (name) .fetch(name, nil) end |
#empty? ⇒ Boolean
196 197 198 |
# File 'lib/rack/mock.rb', line 196 def empty? [201, 204, 304].include? status end |
#match(other) ⇒ Object
178 179 180 |
# File 'lib/rack/mock.rb', line 178 def match(other) body.match other end |