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 Has Select

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

Overview

Shared RSpec test suite that validates the has_select? and has_no_select? predicate methods across all Capybara drivers.

Description

Capybara::SpecHelper provides shared test specifications that driver implementations must pass. This file contains the shared examples for the #has_select? and #has_no_select? methods, exercising selected value verification (single and multiple selects), exact and partial option lists, enabled and disabled option filtering, multiple attribute detection, invisible option and select handling, state transitions after select and unselect operations, locator-less usage, and argument validation.

Usage

Include these shared examples in driver-specific test suites to verify compliance with Capybara's expected behavior contract.

Code Reference

Source Location

Signature

Capybara::SpecHelper.spec '#has_select?' do
  # shared test examples
end

Capybara::SpecHelper.spec '#has_no_select?' do
  # shared test examples
end

Import

require 'capybara/spec/spec_helper'

I/O Contract

Inputs

Name Type Required Description
session Capybara::Session Yes Active session to test against

Outputs

Name Type Description
Test results RSpec::Core::Example Pass/fail assertions

Key Test Scenarios

#has_select?

  • Presence detection -- verifying select fields by label text, name, id, and symbol locators
  • Selected value -- :selected option with single values and arrays for multi-select fields, including state verification after select and unselect operations
  • Invisible selected options -- verifying selected values on hidden selects using visible: :hidden
  • Partial select (with_selected) -- :with_selected option for asserting a subset of selected values in multi-select fields, including non-array single values
  • Exact options -- :options requiring an exact match of all available options (including empty option lists), rejecting subsets and supersets
  • Enabled options -- :enabled_options verifying that listed options exist and are not disabled
  • Disabled options -- :disabled_options verifying that listed options exist and are disabled
  • Partial options (with_options) -- :with_options asserting a subset of available options, including invisible option support via visible: :hidden
  • Multiple attribute -- :multiple option distinguishing between single and multi-select fields
  • Invalid option validation -- raising ArgumentError with a descriptive message listing all valid options when an unknown option is passed
  • Locator-less usage -- calling has_select? without a locator, filtering by :with_options or :with_selected only

#has_no_select?

  • Absence detection -- verifying true when selects do not match and false when they do
  • Selected value (inverse) -- :selected option with single values and arrays, verifying state after select and unselect
  • Partial select (inverse) -- :with_selected with arrays and non-array values
  • Exact options (inverse) -- :options inverse logic rejecting exact matches
  • Partial options (inverse) -- :with_options inverse logic
  • Locator-less usage -- calling has_no_select? without a locator, filtering by :with_options, :with_selected, and :id

Related Pages

Page Connections

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