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.
Instance Attribute Summary collapse
-
#errors ⇒ Object
Errors.
-
#original_headers ⇒ Object
readonly
Headers.
Attributes inherited from Response
Attributes included from Response::Helpers
Instance Method Summary collapse
- #=~(other) ⇒ Object
- #body ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(status, headers, body, errors = StringIO.new("")) ⇒ MockResponse
constructor
A new instance of MockResponse.
- #match(other) ⇒ Object
Methods inherited from Response
#[], #[]=, #close, #delete_cookie, #each, #finish, #redirect, #set_cookie, #write
Methods included from Response::Helpers
#client_error?, #content_length, #content_type, #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.
154 155 156 157 158 159 160 |
# File 'lib/rack/mock.rb', line 154 def initialize(status, headers, body, errors=StringIO.new("")) @original_headers = headers @errors = errors.string if errors.respond_to?(:string) @body_string = nil super(body, status, headers) end |
Instance Attribute Details
#errors ⇒ Object
Errors
152 153 154 |
# File 'lib/rack/mock.rb', line 152 def errors @errors end |
#original_headers ⇒ Object (readonly)
Headers
149 150 151 |
# File 'lib/rack/mock.rb', line 149 def original_headers @original_headers end |
Instance Method Details
#=~(other) ⇒ Object
162 163 164 |
# File 'lib/rack/mock.rb', line 162 def =~(other) body =~ other end |
#body ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/rack/mock.rb', line 170 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 |
#empty? ⇒ Boolean
184 185 186 |
# File 'lib/rack/mock.rb', line 184 def empty? [201, 204, 304].include? status end |
#match(other) ⇒ Object
166 167 168 |
# File 'lib/rack/mock.rb', line 166 def match(other) body.match other end |