Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Teamcapybara Capybara Driver Registration

From Leeroopedia
Knowledge Sources
Domains Testing, Driver_Architecture
Last Updated 2026-02-12 00:00 GMT

Overview

A registration pattern that associates a symbolic name with a factory block for lazily constructing browser driver instances.

Description

Driver Registration is the mechanism by which Capybara's pluggable driver architecture works. Rather than instantiating drivers eagerly, each driver is registered as a named block (factory) that receives the Rack application and returns a Capybara::Driver::Base subclass instance. Drivers are stored in a RegistrationContainer and instantiated lazily when a session first uses them.

This pattern enables:

  • Pluggability — Any driver can be registered by name without modifying Capybara's core
  • Lazy instantiation — Browsers are only launched when tests actually need them
  • Per-test configuration — Different tests can use different driver configurations by name

Usage

Use Capybara.register_driver to define custom driver configurations. This is typically done in test setup (spec_helper.rb) before any tests run.

Theoretical Basis

# Abstract registration pattern (not actual code)
register_driver(:name) { |app| DriverClass.new(app, **options) }
# Later, when session needs the driver:
driver_instance = drivers[:name].call(rack_app)

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment