Class: Rack::MockResponse

Inherits:
Object show all
Includes:
Response::Helpers
Defined in:
lib/gems/rack-0.9.1/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

Instance Method Summary collapse

Methods included from Response::Helpers

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

Constructor Details

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

Returns a new instance of MockResponse.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 113

def initialize(status, headers, body, errors=StringIO.new(""))
  @status = status.to_i

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

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

  @errors = errors.string
end

Instance Attribute Details

#bodyObject (readonly)

Body



143
144
145
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 143

def body
  @body
end

#errorsObject

Errors



155
156
157
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 155

def errors
  @errors
end

#headersObject (readonly)

Headers



135
136
137
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 135

def headers
  @headers
end

#original_headersObject (readonly)

Headers



135
136
137
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 135

def original_headers
  @original_headers
end

#statusObject (readonly)

Status



132
133
134
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 132

def status
  @status
end

Instance Method Details

#=~(other) ⇒ Object



145
146
147
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 145

def =~(other)
  @body =~ other
end

#[](field) ⇒ Object



137
138
139
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 137

def [](field)
  headers[field]
end

#match(other) ⇒ Object



149
150
151
# File 'lib/gems/rack-0.9.1/lib/rack/mock.rb', line 149

def match(other)
  @body.match other
end