module Rack::Test::Methods
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). It defines the following methods that are delegated to the current session: :request, :get, :post, :put, :patch, :delete, :options, :head, :custom_request, :follow_redirect!, :header, :env, :set_cookie, :clear_cookies, :authorize, :basic_authorize, :last_response, and :last_request.
Example:
class HomepageTest < Test::Unit::TestCase include Rack::Test::Methods def app MyApp end end
Attributes
Private accessor to avoid uninitialized instance variable warning in Ruby 2.*
Public Instance Methods
Return the currently actively session. This is the session to which the delegated methods are sent.
# File lib/rack/test/methods.rb, line 51 def current_session @_rack_test_current_session ||= rack_test_session end
Create a new session (or reuse an existing session with the given name), and make it the current session for the given block.
# File lib/rack/test/methods.rb, line 57 def with_session(name) session = _rack_test_current_session yield(@_rack_test_current_session = rack_test_session(name)) ensure @_rack_test_current_session = session end