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.

Implementation:Teamcapybara Capybara Spec Rack Test

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

Overview

This test suite validates the Capybara::RackTest driver, covering driver-specific options, session behavior, header management, redirect handling, and CSS handler isolation.

Description

The file begins by running the shared Capybara::SpecHelper specs against a Rack Test session, skipping capabilities not supported by the driver (e.g., JS, modals, screenshots, frames, windows, hover, scroll, shadow DOM). It then defines driver-specific RSpec describe blocks that test behaviors unique to the Rack Test driver: the data-method link option, fill_in warnings for unsupported fill options, multipart file attachment edge cases, label click toggling for checkboxes and radios, form action query rewriting, #send_keys and #active_element unsupported method errors, textarea text versus value semantics, and style method errors. A separate describe block for Capybara::RackTest::Driver tests the :headers option (persistence across link clicks, form submits, and redirects), :follow_redirects option, :redirect_limit option with default and custom limits, and referer header fragment stripping. The file also verifies HTML5 parsing via Capybara.string and ensures CSSHandlers are not polluted by global module includes.

Usage

This spec file is run as part of the Capybara test suite to ensure the Rack Test driver (the default non-JavaScript driver) behaves correctly. It serves as the primary regression test for Capybara::RackTest::Driver and Capybara::RackTest::CSSHandlers.

Code Reference

Source Location

Signature

module TestSessions
  RackTest = Capybara::Session.new(:rack_test, TestApp)
end

skipped_tests = %i[js modals screenshot frames windows send_keys server hover about_scheme download css scroll spatial html_validation shadow_dom active_element]

Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip: skipped_tests do |example|
  # conditional skips for specific test scenarios
end

RSpec.describe Capybara::Session do
  context 'with rack test driver' do
    describe '#driver' do ... end
    describe '#mode' do ... end
    describe '#click_link' do ... end
    describe '#fill_in' do ... end
    describe '#attach_file' do ... end
    describe '#click' do ... end
    describe '#send_keys' do ... end
    describe '#active_element' do ... end
    describe '#text' do ... end
    describe '#style' do ... end
  end
end

RSpec.describe Capybara::RackTest::Driver do
  describe ':headers option' do ... end
  describe ':follow_redirects option' do ... end
  describe ':redirect_limit option' do ... end
end

RSpec.describe 'Capybara::String' do ... end

RSpec.describe Capybara::RackTest::CSSHandlers do ... end

Import

require 'spec_helper'

Key Test Scenarios

  • Shared spec execution -- Runs the full Capybara shared spec suite against the Rack Test driver, skipping JS-dependent and browser-only features
  • Driver and mode identification -- Confirms the session driver is an instance of Capybara::RackTest::Driver and the mode is :rack_test
  • data-method link handling -- Tests the :respect_data_method option for honoring or ignoring data-method attributes on links, including capitalized variants
  • Fill-in warnings -- Verifies that unsupported :fill_options produce a stderr warning rather than silently failing
  • File attachment -- Tests multipart form submission with empty file fields and correct MIME type detection (e.g., text/csv instead of obsolete types)
  • Label click toggling -- Validates that clicking labels toggles associated checkboxes and radio buttons, and that form action queries are rewritten for GET submissions
  • Unsupported method errors -- Ensures #send_keys and #active_element raise Capybara::NotSupportedByDriverError
  • Textarea text vs. value -- Confirms that #text returns original content while #value reflects the set value
  • Style error -- Verifies #style raises NotImplementedError since Rack Test cannot process CSS
  • Headers persistence -- Tests that custom HTTP headers are maintained across link clicks, form submissions, and redirects
  • Redirect behavior -- Tests default redirect following, disabling redirects, referer header fragment stripping, and configurable redirect limits (default 5, custom 21) with Capybara::InfiniteRedirectError
  • HTML5 parsing -- Validates that Capybara.string uses Nokogiri HTML5 parser when available and enabled
  • CSS handler isolation -- Ensures CSSHandlers is not polluted by global RSpec module includes

Related Pages

Page Connections

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