Class: Rack::MockResponse

Inherits:
Response show all
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.

Constant Summary

Constants inherited from Response

Response::CHUNKED

Instance Attribute Summary collapse

Attributes inherited from Response

#header, #length, #status

Instance Method Summary collapse

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

Returns a new instance of MockResponse.



163
164
165
166
167
168
# File 'lib/rack/mock.rb', line 163

def initialize(status, headers, body, errors=StringIO.new(""))
  @original_headers = headers
  @errors           = errors.string if errors.respond_to?(:string)

  super(body, status, headers)
end

Instance Attribute Details

#errorsObject

Errors



161
162
163
# File 'lib/rack/mock.rb', line 161

def errors
  @errors
end

#original_headersObject (readonly)

Headers



158
159
160
# File 'lib/rack/mock.rb', line 158

def original_headers
  @original_headers
end

Instance Method Details

#=~(other) ⇒ Object



170
171
172
# File 'lib/rack/mock.rb', line 170

def =~(other)
  body =~ other
end

#bodyObject



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/rack/mock.rb', line 178

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

Returns:

  • (Boolean)


192
193
194
# File 'lib/rack/mock.rb', line 192

def empty?
  [201, 204, 205, 304].include? status
end

#match(other) ⇒ Object



174
175
176
# File 'lib/rack/mock.rb', line 174

def match(other)
  body.match other
end