Posted almost 9 years ago. Visible to the public. Linked content.

Escaping of quotation marks in Cucumber steps and step definitions

Issue

When you have a Cucumber step like

Copy
Then I should see "Did you see those \"quotation marks\" over there?"

you'll run into trouble. Cucumber won't take your escaped quotation marks.

Workarounds

One workaround is to write the step as regex (since there is a step taking a regex):

Copy
Then I should see /Did you see those "quotation marks" over there\?/

Keep in mind it’s a regex – escape regex characters like '?'.

When you have a Cucumber step like

Copy
Then I should fill in "query" with "\"some phrase\""

The following matcher will match any string that follows after colon and ends at the line end (and this string may include quotes):

Copy
When /^I fill in "([^"]*)" with: (.*)$/ do |field, value| pending # express the regexp above with the code you wish you had end

Using Spreewald

Or you can simply use Spreewald's Multiline String in your Scenario step:

Copy
When I fill in "query" with: """ "some phrase" """

Also see How to use triple quotes inside a Cucumber docstring.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Dominik Schöler
Last edit:
almost 2 years ago
by Dominik Schöler
Keywords:
quotes, escape, cucumber, double
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more