Module: Capybara::Helpers Private

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.

Defined Under Namespace

Classes: Timer

Class Method Summary collapse

Instance Method Summary collapse

Class 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


69
70
71
# File 'lib/capybara/helpers.rb', line 69

def declension(singular, plural, count)
  count == 1 ? singular : plural
end

.inject_asset_host(html, 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 asset_host.

Parameters:

  • html (String)

    HTML code to inject into

  • host (URL)

    (Capybara.asset_host) The host from which assets should be loaded

Returns:

  • (String)

    The modified HTML code


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

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

Deprecated.

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
20
# File 'lib/capybara/helpers.rb', line 17

def normalize_whitespace(text)
  warn 'DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver'
  text.to_s.gsub(/[[:space:]]+/, ' ').strip
end

.timer(expire_in:) ⇒ 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.


79
80
81
# File 'lib/capybara/helpers.rb', line 79

def timer(expire_in:)
  Timer.new(expire_in)
end

.to_regexp(text, exact: false, all_whitespace: false, options: nil) ⇒ Regexp

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

  • exact (Boolean)

    (false) Whether or not this should be an exact text match

  • options (Fixnum, Boolean, nil)

    Options passed to Regexp.new when creating the Regexp

Returns:

  • (Regexp)

    Regexp to match the passed in text and options


32
33
34
35
36
37
38
39
# File 'lib/capybara/helpers.rb', line 32

def to_regexp(text, exact: false, all_whitespace: false, options: nil)
  return text if text.is_a?(Regexp)

  escaped = Regexp.escape(text)
  escaped = escaped.gsub('\\ ', '[[:blank:]]') if all_whitespace
  escaped = "\\A#{escaped}\\z" if exact
  Regexp.new(escaped, options)
end

Instance Method Details

#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.


74
# File 'lib/capybara/helpers.rb', line 74

def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end