Module: Rack::Test::Methods
- Extended by:
- Forwardable
- Defined in:
- lib/rack/test/methods.rb
Overview
This module serves as the primary integration point for using Rack::Test in a testing environment. It depends on an app method being defined in the same context, and provides the Rack::Test API methods (see Rack::Test::Session for their documentation).
Example:
class HomepageTest < Test::Unit::TestCase
  include Rack::Test::Methods
  def app
    MyApp.new
  end
end
Constant Summary collapse
- METHODS =
- [ :request, :get, :post, :put, :delete, :options, :head, :follow_redirect!, :header, :set_cookie, :clear_cookies, :authorize, :basic_authorize, :digest_authorize, :last_response, :last_request ] 
Instance Method Summary collapse
- 
  
    
      #_current_session_names  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    :nodoc:. 
- 
  
    
      #build_rack_mock_session  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    :nodoc:. 
- 
  
    
      #build_rack_test_session(name)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    :nodoc:. 
- 
  
    
      #current_session  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    :nodoc:. 
- 
  
    
      #rack_mock_session(name = :default)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    :nodoc:. 
- 
  
    
      #rack_test_session(name = :default)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    :nodoc:. 
- 
  
    
      #with_session(name) {|rack_test_session(name)| ... } ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    :nodoc:. 
Instance Method Details
#_current_session_names ⇒ Object
:nodoc:
| 55 56 57 | # File 'lib/rack/test/methods.rb', line 55 def _current_session_names # :nodoc: @_current_session_names ||= [:default] end | 
#build_rack_mock_session ⇒ Object
:nodoc:
| 30 31 32 | # File 'lib/rack/test/methods.rb', line 30 def build_rack_mock_session # :nodoc: Rack::MockSession.new(app) end | 
#build_rack_test_session(name) ⇒ Object
:nodoc:
| 41 42 43 | # File 'lib/rack/test/methods.rb', line 41 def build_rack_test_session(name) # :nodoc: Rack::Test::Session.new(rack_mock_session(name)) end | 
#current_session ⇒ Object
:nodoc:
| 45 46 47 | # File 'lib/rack/test/methods.rb', line 45 def current_session # :nodoc: rack_test_session(_current_session_names.last) end | 
#rack_mock_session(name = :default) ⇒ Object
:nodoc:
| 23 24 25 26 27 28 | # File 'lib/rack/test/methods.rb', line 23 def rack_mock_session(name = :default) # :nodoc: return build_rack_mock_session unless name @_rack_mock_sessions ||= {} @_rack_mock_sessions[name] ||= build_rack_mock_session end | 
#rack_test_session(name = :default) ⇒ Object
:nodoc:
| 34 35 36 37 38 39 | # File 'lib/rack/test/methods.rb', line 34 def rack_test_session(name = :default) # :nodoc: return build_rack_test_session(name) unless name @_rack_test_sessions ||= {} @_rack_test_sessions[name] ||= build_rack_test_session(name) end | 
#with_session(name) {|rack_test_session(name)| ... } ⇒ Object
:nodoc:
| 49 50 51 52 53 | # File 'lib/rack/test/methods.rb', line 49 def with_session(name) # :nodoc: _current_session_names.push(name) yield rack_test_session(name) _current_session_names.pop end |