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.



64
65
66
67
68
69
70
# File 'lib/capybara/helpers.rb', line 64

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

#inject_asset_host(html) ⇒ 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`.



43
44
45
46
47
48
49
50
51
52
# File 'lib/capybara/helpers.rb', line 43

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



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

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.



19
20
21
# File 'lib/capybara/helpers.rb', line 19

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

#to_regexp(text, options = nil) ⇒ 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



31
32
33
# File 'lib/capybara/helpers.rb', line 31

def to_regexp(text, options=nil)
  text.is_a?(Regexp) ? text : Regexp.new(Regexp.escape(normalize_whitespace(text)), options)
end