Class: Rack::MockResponse

Inherits:
Response show all
Defined in:
lib/vendor/rack-1.5.2/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

Attributes inherited from Response

#header, #length, #status

Attributes included from Response::Helpers

#headers

Instance Method Summary collapse

Methods inherited from Response

#[], #[]=, #close, #delete_cookie, #each, #finish, #redirect, #set_cookie, #write

Methods included from Response::Helpers

#bad_request?, #client_error?, #content_length, #content_type, #forbidden?, #include?, #informational?, #invalid?, #location, #method_not_allowed?, #not_found?, #ok?, #redirect?, #redirection?, #server_error?, #successful?, #unprocessable?

Constructor Details

#initialize(status, headers, body, errors = StringIO.new("")) ⇒ MockResponse

Returns a new instance of MockResponse.



156
157
158
159
160
161
162
# File 'lib/vendor/rack-1.5.2/lib/rack/mock.rb', line 156

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

#errorsObject

Errors



154
155
156
# File 'lib/vendor/rack-1.5.2/lib/rack/mock.rb', line 154

def errors
  @errors
end

#original_headersObject (readonly)

Headers



151
152
153
# File 'lib/vendor/rack-1.5.2/lib/rack/mock.rb', line 151

def original_headers
  @original_headers
end

Instance Method Details

#=~(other) ⇒ Object



164
165
166
# File 'lib/vendor/rack-1.5.2/lib/rack/mock.rb', line 164

def =~(other)
  body =~ other
end

#bodyObject



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/vendor/rack-1.5.2/lib/rack/mock.rb', line 172

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)


186
187
188
# File 'lib/vendor/rack-1.5.2/lib/rack/mock.rb', line 186

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

#match(other) ⇒ Object



168
169
170
# File 'lib/vendor/rack-1.5.2/lib/rack/mock.rb', line 168

def match(other)
  body.match other
end