有一个类似的问题@Gherkin in Behat and input validations scenarios
但是不一样。
我的问题是我需要对场景大纲示例或数组进行描述
Given I have a problem with data
| in | this | array |
| how | can | I |
| add | special | characters |
大多数特殊字符都可以,但是引号和管道呢?
special characters example: \|!"#$%&/()=?«»'{}[]'`^~*+ºª-_.:,;<>@ł€¶ŧ←↓→øþĸħŋđðßæ|«»¢“”nµ
谢谢
最佳答案
我知道自发布以来已经过去了一年,但今天遇到了类似的问题,我已经发布了我的解决方案 here .
我在这里复制它以防谷歌群组帖子被删除:
问题
我的 .feature 文件是这样的:
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" |
如您所见,我正在调用相同的步骤来检查其中一个列包含文本中的引号和另一列不包含引号。
当我运行 Behat 测试时,“这里有更多文本”被作为另一个参数,Behat 建议另一个片段。
解决方案
为了解决这个问题,我们必须使用不同于 "的另一个字符来告诉 Behat 存在一个变量,在我的例子中我使用了单引号。
所以,我已经像这样更改了 .feature:
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" |
然后我更新了我的 php 测试实现,如下所示:
/**
* @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)
调用完全相同的实现。
我在阅读 this page 后提出了这个解决方案,以防有人需要。
关于BDD 和 Behat 特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18745962/