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.
Class Method Summary collapse
-
.declension(singular, plural, count) ⇒ Object
private
A poor man’s ‘pluralize`.
-
.inject_asset_host(html, host: Capybara.asset_host) ⇒ String
private
Injects a ‘<base>` tag into the given HTML code, pointing to `Capybara.asset_host`.
- .normalize_whitespace(text) ⇒ String deprecated private Deprecated.
-
.to_regexp(text, exact: false, all_whitespace: false, options: nil) ⇒ Regexp
private
Escapes any characters that would have special meaning in a regexp if text is not a regexp.
Instance Method Summary collapse
- #monotonic_time ⇒ Object private
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.
68 69 70 |
# File 'lib/capybara/helpers.rb', line 68 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 `Capybara.asset_host`.
50 51 52 53 54 55 56 |
# File 'lib/capybara/helpers.rb', line 50 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 |
.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.
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 |
.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
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, ) end |
Instance Method Details
#monotonic_time ⇒ 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.
73 |
# File 'lib/capybara/helpers.rb', line 73 def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end |