Class: Rack::MockResponse

Inherits:
Object
  • Object
show all
Includes:
Response::Helpers
Defined in:
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.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/rack/mock.rb', line 144

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

Instance Attribute Details

#bodyObject (readonly)

Body



172
173
174
# File 'lib/rack/mock.rb', line 172

def body
  @body
end

#errorsObject

Errors



184
185
186
# File 'lib/rack/mock.rb', line 184

def errors
  @errors
end

#headersObject (readonly)

Headers



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

def headers
  @headers
end

#original_headersObject (readonly)

Headers



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

def original_headers
  @original_headers
end

#statusObject (readonly)

Status



161
162
163
# File 'lib/rack/mock.rb', line 161

def status
  @status
end

Instance Method Details

#=~(other) ⇒ Object



174
175
176
# File 'lib/rack/mock.rb', line 174

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

#[](field) ⇒ Object



166
167
168
# File 'lib/rack/mock.rb', line 166

def [](field)
  headers[field]
end

#match(other) ⇒ Object



178
179
180
# File 'lib/rack/mock.rb', line 178

def match(other)
  @body.match other
end