Principle:Teamcapybara Capybara Feature Spec DSL
| Knowledge Sources | |
|---|---|
| Domains | Testing, DSL |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A domain-specific language pattern that provides human-readable aliases for test structure methods to express acceptance tests in business terms.
Description
Feature Spec DSL wraps RSpec's standard structure methods (describe, it, before, let) with aliases that read naturally as acceptance test specifications:
- feature → RSpec.describe (with type: :feature)
- scenario → it
- background → before
- given / given! → let / let!
Additionally, Capybara::DSL provides a page method returning the current Capybara::Session, and delegates all Session DSL methods (visit, find, fill_in, click_on, etc.) to it.
Usage
Use this DSL when writing feature or system specs that describe user-facing workflows. The aliases make tests read like plain English scenarios.
Theoretical Basis
The DSL follows the Facade pattern — it creates a thin layer of readable aliases over existing RSpec and Capybara APIs:
# Abstract pattern (not actual code)
feature = describe(type: :feature)
scenario = it
background = before
given = let
page = Capybara.current_session