Question

There is a similar question @ Gherkin in Behat and input validations scenarios

However is not the same.

My problem is that I need to had to scenario outlines examples or to arrays

Given I have a problem with data
   | in  | this    | array      |
   | how | can     | I          |
   | add | special | characters | 

Most of special characters are ok, but wat about quotes and pipes?

special characters example: \|!"#$%&/()=?«»'{}[]'`^~*+ºª-_.:,;<>@ł€¶ŧ←↓→øþĸħŋđðßæ|«»¢“”nµ

Thanks

Était-ce utile?

La solution

I know that a year has passed since this was posted, but today had a similar problem and I have posted my solution here.

I'm copying it here in case that the google groups post is deleted:

The problem

My .feature file is something like this:

 Then I get a response with "error" equals to "<error>"

 And I get a response with "error" equals to "<error_message>"


 Examples:

 |error                    |  error_message                                                              |

 |NotFoundHttpException    |  Something with quotes "More text here"                     |

As you can see I'm calling the very same step to check one of the columns which contains quotes in the text and another column which don't.

When I run Behat tests, the "More text here" is being taken as another parameter and Behat is suggesting another snippet.

The solution

To fix this we have to use another character different from " to tell Behat that a variable is present, in my case I have used single quotes.

So, I have changed the .feature like this:

 Then I get a response with "error" equals to "<error>"

 And I get a response with "error_message" equals to '<error_message>' escaping quotes

 Examples:

 |error                    |  error_message                                                            |

 |NotFoundHttpException    |  Something with quotes "More text here"                     |

Then I have updated my php tests implementation like this:

/**
 * @Then I get a response with :attibute equals to :value
 * @Then /^I get a response with "([^"]+)" equals to '([^']+)' escaping quotes$/
 */
public function iGetAResponseWithEqualsTo($attibute, $value)

The very same implementation is called.

I came with this solution after reading this page, in case that somebody need it.

Autres conseils

I'm finding on Behat 3.0 that I can just specify strings using '' as a delimiter, e.g.

Then I should see the text 'some "text" with "quotes"', and it works as is out of the box without having to write a custom step.

A viable alternative I've found is to match two step definitions, one with the string to match enclosed in double quotes, and the other in a PyString (triple-quote beneath the step).

Ex.

And the email body should contain
"""
This link with double quotes <a href="http://mockshare.url/file.pdf">DOWNLOAD</a>
"""

The method:

/**
 * Checks that the body of the last accessed email contains a string.
 *
 * @param mixed $body The string or PyString representing text to match.
 *
 * @uses A PyString class sometimes, to help with double quotes in the matched string. 
 * (Hence the string casting).
 *
 * @Then the email body should contain :body
 * @Then the email body should contain
 *
 * @return void
 */
public function theEmailBodyShouldContain($body)
{
    assertContains((string) $body, $this->body);
}//end theEmailBodyShouldContain()

Found the issue it needs to have an escaping backslash "\"

I've tried this, but on the editor I'm using it didn't assume, so needed to do functional test to verify, and using \" or \| worked as expected.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top