Search code examples
bddbehatgherkin

BDD and Behat special characters


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


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.