module Rack::Test::Methods

def build_rack_test_session(_name) # :nodoc:

:nodoc:
Create a new Rack::Test::Session for #app.
def build_rack_test_session(_name) # :nodoc:
  if respond_to?(:build_rack_mock_session, true)
    # Backwards compatibility for capybara
    build_rack_mock_session
  else
    if respond_to?(:default_host)
      Session.new(app, default_host)
    else
      Session.new(app)
    end
  end
end

def current_session

which the delegated methods are sent.
Return the currently actively session. This is the session to
def current_session
  @_rack_test_current_session ||= rack_test_session
end

def rack_test_session(name = :default) # :nodoc:

:nodoc:
rack session. Always use a new session if name is nil.
Return the existing session with the given name, or a new
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

def with_session(name)

and make it the current session for the given block.
Create a new session (or reuse an existing session with the given name),
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