Class: Rack::MockResponse
- Defined in:
 - lib/rack/mock_response.rb
 
Overview
Rack::MockResponse provides useful helpers for testing your apps. Usually, you don’t create the MockResponse on your own, but use MockRequest.
Defined Under Namespace
Classes: Cookie
Constant Summary
Constants inherited from Response
Response::CHUNKED, Response::STATUS_WITH_NO_ENTITY_BODY
Instance Attribute Summary collapse
- 
  
    
      #cookies  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Headers.
 - 
  
    
      #errors  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Errors.
 - 
  
    
      #original_headers  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Headers.
 
Attributes inherited from Response
Instance Method Summary collapse
- #=~(other) ⇒ Object
 - #body ⇒ Object
 - #cookie(name) ⇒ Object
 - #empty? ⇒ Boolean
 - 
  
    
      #initialize(status, headers, body, errors = nil)  ⇒ MockResponse 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of MockResponse.
 - #match(other) ⇒ Object
 
Methods inherited from Response
#chunked?, #close, #delete_header, #each, #finish, #get_header, #has_header?, #no_entity_body?, #redirect, #set_header, #write
Methods included from Response::Helpers
#accepted?, #add_header, #bad_request?, #cache!, #cache_control, #cache_control=, #client_error?, #content_length, #content_type, #content_type=, #created?, #delete_cookie, #do_not_cache!, #etag, #etag=, #forbidden?, #include?, #informational?, #invalid?, #location, #location=, #media_type, #media_type_params, #method_not_allowed?, #moved_permanently?, #no_content?, #not_acceptable?, #not_found?, #ok?, #precondition_failed?, #redirect?, #redirection?, #request_timeout?, #server_error?, #set_cookie, #set_cookie_header, #set_cookie_header=, #successful?, #unauthorized?, #unprocessable?
Constructor Details
#initialize(status, headers, body, errors = nil) ⇒ MockResponse
Returns a new instance of MockResponse.
      47 48 49 50 51 52 53 54 55 56 57 58 59 60  | 
    
      # File 'lib/rack/mock_response.rb', line 47 def initialize(status, headers, body, errors = nil) @original_headers = headers if errors @errors = errors.string if errors.respond_to?(:string) else @errors = "" end super(body, status, headers) @cookies = buffered_body! end  | 
  
Instance Attribute Details
#cookies ⇒ Object (readonly)
Headers
      42 43 44  | 
    
      # File 'lib/rack/mock_response.rb', line 42 def @cookies end  | 
  
#errors ⇒ Object
Errors
      45 46 47  | 
    
      # File 'lib/rack/mock_response.rb', line 45 def errors @errors end  | 
  
#original_headers ⇒ Object (readonly)
Headers
      42 43 44  | 
    
      # File 'lib/rack/mock_response.rb', line 42 def original_headers @original_headers end  | 
  
Instance Method Details
#=~(other) ⇒ Object
      62 63 64  | 
    
      # File 'lib/rack/mock_response.rb', line 62 def =~(other) body =~ other end  | 
  
#body ⇒ Object
      70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90  | 
    
      # File 'lib/rack/mock_response.rb', line 70 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) ⇒ Object
      96 97 98  | 
    
      # File 'lib/rack/mock_response.rb', line 96 def (name) .fetch(name, nil) end  | 
  
#empty? ⇒ Boolean
      92 93 94  | 
    
      # File 'lib/rack/mock_response.rb', line 92 def empty? [201, 204, 304].include? status end  | 
  
#match(other) ⇒ Object
      66 67 68  | 
    
      # File 'lib/rack/mock_response.rb', line 66 def match(other) body.match other end  |