Class Rack::MockResponse
In: lib/rack/mock.rb
Parent: Object

Rack::MockResponse provides useful helpers for testing your apps. Usually, you don’t create the MockResponse on your own, but use MockRequest.

Methods

Attributes

body  [R]  Body
errors  [RW]  Errors
headers  [R]  Headers
original_headers  [R]  Headers
status  [R]  Status

Public Class methods

[Source]

     # File lib/rack/mock.rb, line 108
108:     def initialize(status, headers, body, errors=StringIO.new(""))
109:       @status = status.to_i
110: 
111:       @original_headers = headers
112:       @headers = Rack::Utils::HeaderHash.new
113:       headers.each { |field, values|
114:         values.each { |value|
115:           @headers[field] = value
116:         }
117:       }
118: 
119:       @body = ""
120:       body.each { |part| @body << part }
121: 
122:       @errors = errors.string
123:     end

Public Instance methods

[Source]

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

[Source]

     # File lib/rack/mock.rb, line 150
150:     def [](field)
151:       headers[field]
152:     end

[Source]

     # File lib/rack/mock.rb, line 133
133:     def client_error?;  @status >= 400 && @status < 500;       end

[Source]

     # File lib/rack/mock.rb, line 158
158:     def content_length
159:       cl = headers["Content-Length"]
160:       cl ? cl.to_i : cl
161:     end

[Source]

     # File lib/rack/mock.rb, line 154
154:     def content_type
155:       headers["Content-Type"]
156:     end

[Source]

     # File lib/rack/mock.rb, line 141
141:     def empty?;         [201, 204, 304].include?      @status; end

[Source]

     # File lib/rack/mock.rb, line 137
137:     def forbidden?;     @status == 403;                        end

[Source]

     # File lib/rack/mock.rb, line 146
146:     def include?(header)
147:       !!headers[header]
148:     end

[Source]

     # File lib/rack/mock.rb, line 130
130:     def informational?; @status >= 100 && @status < 200;       end

[Source]

     # File lib/rack/mock.rb, line 128
128:     def invalid?;       @status < 100 || @status >= 600;       end

[Source]

     # File lib/rack/mock.rb, line 163
163:     def location
164:       headers["Location"]
165:     end

[Source]

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

[Source]

     # File lib/rack/mock.rb, line 138
138:     def not_found?;     @status == 404;                        end

[Source]

     # File lib/rack/mock.rb, line 136
136:     def ok?;            @status == 200;                        end

[Source]

     # File lib/rack/mock.rb, line 140
140:     def redirect?;      [301, 302, 303, 307].include? @status; end

[Source]

     # File lib/rack/mock.rb, line 132
132:     def redirection?;   @status >= 300 && @status < 400;       end

[Source]

     # File lib/rack/mock.rb, line 134
134:     def server_error?;  @status >= 500 && @status < 600;       end

[Source]

     # File lib/rack/mock.rb, line 131
131:     def successful?;    @status >= 200 && @status < 300;       end

[Validate]