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

Public Class Methods

Calls superclass method Rack::Response::new
# File lib/rack/mock_response.rb, line 24
def initialize(status, headers, body, errors = nil)
  @original_headers = headers

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

  super(body, status, headers)

  @cookies = parse_cookies_from_header
  buffered_body!
end

Public Instance Methods

# File lib/rack/mock_response.rb, line 39
def =~(other)
  body =~ other
end
# File lib/rack/mock_response.rb, line 47
def body
  return @buffered_body if defined?(@buffered_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
  buffer = @buffered_body = String.new

  @body.each do |chunk|
    buffer << chunk
  end

  return buffer
end
# File lib/rack/mock_response.rb, line 69
def empty?
  [201, 204, 304].include? status
end
# File lib/rack/mock_response.rb, line 43
def match(other)
  body.match other
end