Module: Calabash::Cucumber::QueryHelpers
- Included in:
- Core
- Defined in:
- lib/calabash-cucumber/query_helpers.rb
Overview
A module of methods that can help you construct queries.
Instance Method Summary collapse
-
#escape_backslashes(str) ⇒ String
call this method to properly escape blackslashes () in Calabash methods (queries and uia actions).
-
#escape_newlines(str) ⇒ String
call this method to properly escape newlines (n) in Calabash methods (queries and uia actions).
-
#escape_quotes(str) ⇒ String
call this method to properly escape single quotes in Calabash queries Calabash iOS has some annoying rules for text containing single quotes.
-
#escape_string(str) ⇒ String
call this method to properly escape strings with single quotes and black slashes in methods (queries and uia actions) Calabash iOS has some annoying rules for text containing single quotes, and even moreso for backslash ().
Instance Method Details
#escape_backslashes(str) ⇒ String
In ruby it is important to remember that “\” is a *single character* string containing a backslash: \
call this method to properly escape blackslashes () in Calabash methods (queries and uia actions). Calabash iOS has some annoying rules for text containing single quotes, and even moreso for backslash (). This helper frees you from manual escaping.
35 36 37 38 |
# File 'lib/calabash-cucumber/query_helpers.rb', line 35 def escape_backslashes(str) backslash = "\\" str.gsub(backslash, backslash*4) end |
#escape_newlines(str) ⇒ String
In ruby it is important to remember that “n” is a *single character* string containing a new-line.
call this method to properly escape newlines (n) in Calabash methods (queries and uia actions). This helper frees you from manual escaping. Note entering a ‘newline’ character only works in iOS UITextViews
53 54 55 56 |
# File 'lib/calabash-cucumber/query_helpers.rb', line 53 def escape_newlines(str) nl = "\n" str.gsub(nl, "\\n") end |
#escape_quotes(str) ⇒ String
call this method to properly escape single quotes in Calabash queries Calabash iOS has some annoying rules for text containing single quotes. This helper frees you from manual escaping.
66 67 68 |
# File 'lib/calabash-cucumber/query_helpers.rb', line 66 def escape_quotes(str) str.gsub("'", "\\\\'") end |
#escape_string(str) ⇒ String
call this method to properly escape strings with single quotes and black slashes in methods (queries and uia actions) Calabash iOS has some annoying rules for text containing single quotes, and even moreso for backslash (). This helper frees you from manual escaping.
17 18 19 |
# File 'lib/calabash-cucumber/query_helpers.rb', line 17 def escape_string(str) escape_newlines(escape_quotes(escape_backslashes(str))) end |