Module: Capybara::Helpers Private
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
-
#declension(singular, plural, count) ⇒ Object
private
A poor man’s ‘pluralize`.
-
#failure_message(description, options = {}) ⇒ Object
private
Generates a failure message given a description of the query and count options.
-
#inject_asset_host(html) ⇒ String
private
Injects a ‘<base>` tag into the given HTML code, pointing to `Capybara.asset_host`.
-
#matches_count?(count, options = {}) ⇒ Boolean
private
Checks if the given count matches the given count options.
-
#normalize_whitespace(text) ⇒ String
private
Normalizes whitespace space by stripping leading and trailing whitespace and replacing sequences of whitespace characters with a single space.
-
#to_regexp(text) ⇒ String
private
Escapes any characters that would have special meaning in a regexp if text is not a regexp.
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 gramatically correct error message.
113 114 115 116 117 118 119 |
# File 'lib/capybara/helpers.rb', line 113 def declension(singular, plural, count) if count == 1 singular else plural end end |
#failure_message(description, options = {}) ⇒ 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.
Generates a failure message given a description of the query and count options.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/capybara/helpers.rb', line 89 def (description, ={}) = "expected to find #{description}" if [:count] << " #{[:count]} #{declension('time', 'times', [:count])}" elsif [:between] << " between #{[:between].first} and #{[:between].last} times" elsif [:maximum] << " at most #{[:maximum]} #{declension('time', 'times', [:maximum])}" elsif [:minimum] << " at least #{[:minimum]} #{declension('time', 'times', [:minimum])}" 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`.
42 43 44 45 46 47 48 49 50 |
# File 'lib/capybara/helpers.rb', line 42 def inject_asset_host(html) if Capybara.asset_host if Nokogiri::HTML(html).css("base").empty? and match = html.match(/<head[^<]*?>/) html.clone.insert match.end(0), "<base href='#{Capybara.asset_host}' />" end else html end end |
#matches_count?(count, options = {}) ⇒ Boolean
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.
Checks if the given count matches the given count options. By default, when no options are given, count should be larger than zero.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/capybara/helpers.rb', line 63 def matches_count?(count, ={}) case when [:between] [:between] === count when [:count] Integer([:count]) == count when [:maximum] Integer([:maximum]) >= count when [:minimum] Integer([:minimum]) <= count else count > 0 end 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.
18 19 20 |
# File 'lib/capybara/helpers.rb', line 18 def normalize_whitespace(text) text.to_s.gsub(/[[:space:]]+/, ' ').strip end |
#to_regexp(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.
Escapes any characters that would have special meaning in a regexp if text is not a regexp
30 31 32 |
# File 'lib/capybara/helpers.rb', line 30 def to_regexp(text) text.is_a?(Regexp) ? text : Regexp.new(Regexp.escape(normalize_whitespace(text))) end |