class Rack::MockResponse - rack-1.6.2 Documentation

# 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

errors[RW]

Errors

original_headers[R]

Headers

### Public Class Methods

new(status, headers, body, errors=StringIO.new("")) click to toggle source
Calls superclass method Rack::Response.new

    # File lib/rack/mock.rb, line 164
    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

### Public Instance Methods

=~(other) click to toggle source

    # File lib/rack/mock.rb, line 172
    def =~(other)
      body =~ other
    end

body() click to toggle source
Calls superclass method

    # File lib/rack/mock.rb, line 180
    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?() click to toggle source

    # File lib/rack/mock.rb, line 194
    def empty?
      [201, 204, 205, 304].include? status
    end

match(other) click to toggle source

    # File lib/rack/mock.rb, line 176
    def match(other)
      body.match other
    end