Class: Rack::MockResponse

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

Instance Method Summary (collapse)

Constructor Details

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

Returns a new instance of MockResponse



156
157
158
159
160
161
162
# File 'rack/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

- (void) body Originally defined in class Response

Returns the value of attribute body

- (void) errors

Errors



154
155
156
# File 'rack/rack/mock.rb', line 154

def errors
  @errors
end

- (void) header (readonly) Also known as: headers Originally defined in class Response

Returns the value of attribute header

- (void) headers (readonly) Originally defined in module Response::Helpers

Headers

- (void) length Originally defined in class Response

Returns the value of attribute length

- (void) original_headers (readonly)

Headers



151
152
153
# File 'rack/rack/mock.rb', line 151

def original_headers
  @original_headers
end

- (void) original_headers (readonly) Originally defined in module Response::Helpers

Headers

- (void) status Originally defined in class Response

Returns the value of attribute status

Instance Method Details

- (void) =~(other)



164
165
166
# File 'rack/rack/mock.rb', line 164

def =~(other)
  body =~ other
end

- (void) body



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'rack/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

- (Boolean) empty?

Returns:

  • (Boolean)


186
187
188
# File 'rack/rack/mock.rb', line 186

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

- (void) match(other)



168
169
170
# File 'rack/rack/mock.rb', line 168

def match(other)
  body.match other
end