Module: Capybara::Helpers

Defined in:
lib/capybara/helpers.rb

Class Method Summary collapse

Class Method Details

.normalize_whitespace(text) ⇒ String

Normalizes whitespace space by stripping leading and trailing whitespace and replacing sequences of whitespace characters with a single space.

Parameters:

  • text (String)

    Text to normalize

Returns:

  • (String)

    Normalized text



15
16
17
# File 'lib/capybara/helpers.rb', line 15

def normalize_whitespace(text)
  text.to_s.gsub(/[[:space:]]+/, ' ').strip
end

.to_regexp(text) ⇒ String

Escapes any characters that would have special meaning in a regexp if text is not a regexp

Parameters:

  • text (String)

    Text to escape

Returns:

  • (String)

    Escaped text



27
28
29
# File 'lib/capybara/helpers.rb', line 27

def to_regexp(text)
  text.is_a?(Regexp) ? text : Regexp.escape(normalize_whitespace(text))
end