Method: Capybara.using_session

Defined in:
lib/capybara.rb

.using_session(name_or_session, &block) ⇒ Object

Yield a block using a specific session name or Session instance.



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/capybara.rb', line 358

def using_session(name_or_session, &block)
  previous_session = current_session
  previous_session_info = {
    specified_session: specified_session,
    session_name: session_name,
    current_driver: current_driver,
    app: app
  }
  self.specified_session = self.session_name = nil
  if name_or_session.is_a? Capybara::Session
    self.specified_session = name_or_session
  else
    self.session_name = name_or_session
  end

  if block.arity.zero?
    yield
  else
    yield current_session, previous_session
  end
ensure
  self.session_name, self.specified_session = previous_session_info.values_at(:session_name, :specified_session)
  self.current_driver, self.app = previous_session_info.values_at(:current_driver, :app) if threadsafe
end