Module: Dommy::Internal::ElementMatching

Defined in:
lib/dommy/internal/element_matching.rb

Overview

Element-type-specific finders for links, forms, selects, and checkable fields. Lives in dommy core so that companion gems (currently dommy-rails) share a single finder implementation instead of re-implementing the selector / filter logic per gem.

Attribute criteria (href:, action:, name:) accept a String (exact match), a Regexp, or any object responding to matches? — the extension point dommy-rails uses to inject URL normalization.

Class Method Summary collapse



37
38
39
40
41
42
# File 'lib/dommy/internal/element_matching.rb', line 37

def find_selects(scope, name: nil, label: nil)
  selects = scope.query_selector_all("select").to_a
  selects = selects.select { |el| attribute_matches?(el, "name", name) } if name
  selects = selects.select { |el| field_label_matches?(el, label) } if label
  selects
end

.form_method_matches?(form, expected_method) ⇒ Boolean

Returns:



99
100
101
102
103
104
105
106
# File 'lib/dommy/internal/element_matching.rb', line 99

def form_method_matches?(form, expected_method)
  actual_method = form.get_attribute("method").to_s.downcase
  if actual_method == "post"
    hidden_method = form.query_selector("input[type='hidden'][name='_method']")
    actual_method = hidden_method.get_attribute("value").to_s.downcase if hidden_method
  end
  actual_method == expected_method.to_s.downcase
end