Module: Capybara::Helpers Private

Extended by:
Helpers
Included in:
Helpers
Defined in:
lib/capybara/helpers.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#declension(singular, plural, count) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A poor man's `pluralize`. Given two declensions, one singular and one plural, as well as a count, this will pick the correct declension. This way we can generate grammatically correct error message.

Parameters:

  • singular (String)

    The singular form of the word

  • plural (String)

    The plural form of the word

  • count (Integer)

    The number of items



68
69
70
71
72
73
74
# File 'lib/capybara/helpers.rb', line 68

def declension(singular, plural, count)
  if count == 1
    singular
  else
    plural
  end
end

#inject_asset_host(html, asset_host = Capybara.asset_host) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Injects a `<base>` tag into the given HTML code, pointing to `Capybara.asset_host`.

Parameters:

  • html (String)

    HTML code to inject into

Returns:

  • (String)

    The modified HTML code



47
48
49
50
51
52
53
54
55
56
# File 'lib/capybara/helpers.rb', line 47

def inject_asset_host(html, asset_host = Capybara.asset_host)
  if asset_host && Nokogiri::HTML(html).css("base").empty?
    match = html.match(/<head[^<]*?>/)
    if match
      return html.clone.insert match.end(0), "<base href='#{asset_host}' />"
    end
  end

  html
end

#monotonic_timeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



77
78
79
# File 'lib/capybara/helpers.rb', line 77

def monotonic_time
  Process.clock_gettime Process::CLOCK_MONOTONIC
end

#normalize_whitespace(text) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



17
18
19
# File 'lib/capybara/helpers.rb', line 17

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

#to_regexp(text, regexp_options = nil, exact = false) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



29
30
31
32
33
34
35
36
37
# File 'lib/capybara/helpers.rb', line 29

def to_regexp(text, regexp_options = nil, exact = false)
  if text.is_a?(Regexp)
    text
  else
    escaped = Regexp.escape(normalize_whitespace(text))
    escaped = "\\A#{escaped}\\z" if exact
    Regexp.new(escaped, regexp_options)
  end
end