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.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# 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

Instance Attribute Details

#bodyObject (readonly)

Body



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

def body
  @body
end

#errorsObject

Errors



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

def errors
  @errors
end

#headersObject (readonly)

Headers



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

def headers
  @headers
end

#original_headersObject (readonly)

Headers



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

def original_headers
  @original_headers
end

#statusObject (readonly)

Status



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

def status
  @status
end

Instance Method Details

#=~(other) ⇒ Object



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

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

#[](field) ⇒ Object



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

def [](field)
  headers[field]
end

#match(other) ⇒ Object



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

def match(other)
  @body.match other
end