Class: Rack::MockResponse
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Response
|
|
Instance Chain:
self,
Response ,
Response::Helpers
|
|
Inherits: |
Rack::Response
|
Defined in: | lib/rack/mock_response.rb |
Overview
MockResponse
provides useful helpers for testing your apps. Usually, you don’t create the MockResponse
on your own, but use MockRequest
.
Constant Summary
Response
- Inherited
Class Method Summary
-
.[](body = nil, status = 200, headers = {})
Alias for Response.new.
- .new(status, headers, body, errors = nil) ⇒ MockResponse constructor
Response
- Inherited
Instance Attribute Summary
- #cookies readonly
- #empty? ⇒ Boolean readonly
-
#errors
rw
Errors.
- #original_headers readonly
Response
- Inherited
Response::Helpers
- Included
#accepted?, #bad_request?, #cache_control, #cache_control=, #client_error?, | |
#content_type | Get the content type of the response. |
#content_type= | Set the content type of the response. |
#created?, #etag, #etag=, #forbidden?, #informational?, #invalid?, #location, #location=, #method_not_allowed?, #moved_permanently?, #no_content?, #not_acceptable?, #not_found?, #ok?, #precondition_failed?, #redirect?, #redirection?, #request_timeout?, #server_error?, #set_cookie_header, #set_cookie_header=, #successful?, #unauthorized?, #unprocessable? |
Instance Method Summary
- #=~(other)
- #body
- #cookie(name)
- #match(other)
- #identify_cookie_attributes(cookie_filling) private
- #parse_cookies_from_header private
Response
- Inherited
#[] | Alias for Response#get_header. |
#[]= | Alias for Response#set_header. |
#close, #delete_header, #each, | |
#finish | Generate a response array consistent with the requirements of the SPEC. |
#get_header, #has_header?, #redirect, #set_header, | |
#to_a | Alias for Response#finish. |
#write | Append a chunk to the response body. |
Response::Helpers
- Included
#add_header | Add a header that may have multiple values. |
#cache! | Specify that the content should be cached. |
#content_length, #delete_cookie, | |
#do_not_cache! | Specifies that the content shouldn’t be cached. |
#include?, #media_type, #media_type_params, #set_cookie |
Constructor Details
.new(status, headers, body, errors = nil) ⇒ MockResponse
Class Method Details
.[](body = nil, status = 200, headers = {})
Alias for Response.new.
# File 'lib/rack/mock_response.rb', line 15
alias [] new
Instance Attribute Details
#cookies (readonly)
[ GitHub ]# File 'lib/rack/mock_response.rb', line 19
attr_reader :original_headers, :
#empty? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rack/mock_response.rb', line 69
def empty? [201, 204, 304].include? status end
#errors (rw)
Errors
# File 'lib/rack/mock_response.rb', line 22
attr_accessor :errors
#original_headers (readonly)
[ GitHub ]# File 'lib/rack/mock_response.rb', line 19
attr_reader :original_headers, :
Instance Method Details
#=~(other)
[ GitHub ]# File 'lib/rack/mock_response.rb', line 39
def =~(other) body =~ other end
#body
[ GitHub ]# File 'lib/rack/mock_response.rb', line 47
def body return @buffered_body if defined?(@buffered_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 buffer = @buffered_body = String.new @body.each do |chunk| buffer << chunk end return buffer end
#cookie(name)
[ GitHub ]# File 'lib/rack/mock_response.rb', line 73
def (name) .fetch(name, nil) end
#identify_cookie_attributes(cookie_filling) (private)
[ GitHub ]# File 'lib/rack/mock_response.rb', line 100
def ( ) = .split(';') = Hash.new .store('value', [0].strip) .drop(1).each do |bit| if bit.include? '=' , attribute_value = bit.split('=', 2) .store( .strip.downcase, attribute_value.strip) end if bit.include? 'secure' .store('secure', true) end end if .key? 'max-age' .store('expires', Time.now + ['max-age'].to_i) elsif .key? 'expires' .store('expires', Time.httpdate( ['expires'])) end end
#match(other)
[ GitHub ]# File 'lib/rack/mock_response.rb', line 43
def match(other) body.match other end
#parse_cookies_from_header (private)
[ GitHub ]# File 'lib/rack/mock_response.rb', line 79
def = Hash.new = headers['set-cookie'] if && ! .empty? Array( ).each do || , = .split('=', 2) = = CGI::Cookie.new( 'name' => .strip, 'value' => .fetch('value'), 'path' => .fetch('path', nil), 'domain' => .fetch('domain', nil), 'expires' => .fetch('expires', nil), 'secure' => .fetch('secure', false) ) .store(, ) end end end