class Rack::MockResponse

Rack::MockResponse provides useful helpers for testing your apps. Usually, you don’t create the MockResponse on your own, but use MockRequest.

Attributes

body[R]

Body

errors[RW]

Errors

headers[R]

Headers

original_headers[R]

Headers

status[R]

Status

Public Class Methods

new(status, headers, body, errors=StringIO.new("")) click to toggle source
# File lib/rack/mock.rb, line 145
def initialize(status, headers, body, errors=StringIO.new(""))
  @status = status.to_i

  @original_headers = headers
  @headers = Rack::Utils::HeaderHash.new
  headers.each { |field, values|
    @headers[field] = values
    @headers[field] = ""  if values.empty?
  }

  @body = ""
  body.each { |part| @body << part }

  @errors = errors.string if errors.respond_to?(:string)
end

Public Instance Methods

=~(other) click to toggle source
# File lib/rack/mock.rb, line 175
def =~(other)
  @body =~ other
end
[](field) click to toggle source
# File lib/rack/mock.rb, line 167
def [](field)
  headers[field]
end
match(other) click to toggle source
# File lib/rack/mock.rb, line 179
def match(other)
  @body.match other
end