我知道自发布以来已经过去了一年,但今天遇到了类似的问题,我已经发布了我的解决方案here https://groups.google.com/forum/#!topic/behat/hFQAJ6q7Hm8.
我将其复制到此处,以防 Google 群组帖子被删除:
问题
我的 .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)
调用完全相同的实现。
阅读后我提出了这个解决方案这一页 http://knplabs.com/en/blog/behat-like-a-boss-wirting-custom-steps,以防有人需要。