Read more

Escaping of quotation marks in Cucumber steps and step definitions

Dominik Schöler
February 25, 2011Software engineer at makandra GmbH

Issue

When you have a Cucumber step like

Then I should see "Did you see those \"quotation marks\" over there?"
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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):

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

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

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

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 Show archive.org snapshot Multiline String in your Scenario step:

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

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

Posted by Dominik Schöler to makandra dev (2011-02-25 10:27)