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

Instance Method Details

#escape_backslashes(str) ⇒ String

Note:

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.

Examples:

quoted = escape_backslashes("Karl's \\ annoying problem")
# => "Karl's \\\\ annoying problem"

Parameters:

  • str (String)

    string to escape

Returns:

  • (String)

    escaped version of str



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

Note:

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

Examples:

quoted = escape_newlines("Karl's \n annoying problem")
# => "Karl's \\n annoying problem"

Parameters:

  • str (String)

    string to escape

Returns:

  • (String)

    escaped version of str



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.

Examples:

quoted = escape_quotes("Karl's child")
# => "Karl\\'s child"

Parameters:

  • str (String)

    string to escape

Returns:

  • (String)

    escaped version of str



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.

Examples:

quoted = escape_string("Karl's \\ annoying problem")
# => "Karl\\'s \\\\ annoying problem"

Parameters:

  • str (String)

    string to escape

Returns:

  • (String)

    escaped version of str



17
18
19
# File 'lib/calabash-cucumber/query_helpers.rb', line 17

def escape_string(str)
  escape_newlines(escape_quotes(escape_backslashes(str)))
end