module Capybara::Helpers
def declension(singular, plural, count)
-
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 inject_asset_host(html, host: Capybara.asset_host)
-
(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? match = html.match(/<head[^<]*?>/) return html.clone.insert match.end(0), "<base href='#{host}' />" if match end html 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)
-
(String)- Normalized text
Parameters:
-
text(String) -- Text to normalize
Deprecated:
def normalize_whitespace(text) warn "DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver" text.to_s.gsub(/[[:space:]]+/, ' ').strip end
def to_regexp(text, exact: false, all_whitespace: false, options: nil)
-
(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