module Rack::Test::Methods

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