module Capybara::Helpers

def declension(singular, plural, count)

Parameters:
  • count (Integer) -- The number of items
  • plural (String) -- The plural form of the word
  • singular (String) -- The singular form of the word
def declension(singular, plural, count)
  count == 1 ? singular : plural
end

def filter_backtrace(trace)

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

def inject_asset_host(html, host: Capybara.asset_host)

Returns:
  • (String) - The modified HTML code

Parameters:
  • host (URL) -- (Capybara.asset_host) The host from which assets should be loaded
  • html (String) -- HTML code to inject into
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

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

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

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

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

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

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

def monotonic_time; Time.now.to_f; end

def monotonic_time; Time.now.to_f; end

def normalize_whitespace(text)

Returns:
  • (String) - Normalized text

Parameters:
  • text (String) -- Text to normalize

Deprecated:
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

def timer(expire_in:)

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

def to_regexp(text, exact: false, all_whitespace: false, options: nil)

Returns:
  • (Regexp) - Regexp to match the passed in text and options

Parameters:
  • options (Fixnum, Boolean, nil) -- Options passed to Regexp.new when creating the Regexp
  • exact (Boolean) -- (false) Whether or not this should be an exact text match
  • text (String) -- Text to escape
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

def warn(message, uplevel: 1)

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