123456789_123456789_123456789_123456789_123456789_

Module: Capybara::Helpers Private

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Defined in: lib/capybara/helpers.rb

Class Method Summary

Class Method Details

.declension(singular, plural, count) (mod_func)

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

[ GitHub ]

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

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

.filter_backtrace(trace) (mod_func)

[ GitHub ]

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

def filter_backtrace(trace)
  return 'No backtrace' unless trace

  filter = %r{lib/capybara/|lib/rspec/|lib/minitest/|delegate.rb}
  new_trace = trace.take_while { |line| line !~ filter }
  new_trace = trace.grep_v(filter) if new_trace.empty?
  new_trace = trace.dup if new_trace.empty?

  new_trace.first.split(':in ', 2).first
end

.inject_asset_host(html, host: Capybara.asset_host) ⇒ String (mod_func)

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

Parameters:

  • html (String)

    Capybara.HTML code to inject into

  • host (URL)

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

Returns:

[ GitHub ]

  
# 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

.monotonic_time (mod_func)

See additional method definition at line 89.

See additional method definition at line 91.

See additional method definition at line 93.

[ GitHub ]

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

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

.normalize_whitespace(text) ⇒ String (mod_func)

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

[ GitHub ]

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

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

.timer(expire_in:) (mod_func)

[ GitHub ]

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

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

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

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

[ GitHub ]

  
# 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

.warn(message, uplevel: 1) (mod_func)

[ GitHub ]

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

def warn(message, uplevel: 1)
  Kernel.warn(message, uplevel: uplevel)
end