BDD和Behat特殊字符 [英] BDD and Behat special characters

查看:85
本文介绍了BDD和Behat特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@ 小黄瓜和输入验证场景中的小黄瓜

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

但是不一样.

我的问题是我需要场景概述示例或数组

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µ

谢谢

推荐答案

我知道自发布该文档以来已经过去了一年,但是今天也遇到了类似的问题,我已经发布了我的解决方案

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

如果要将Google网上论坛帖子删除,我将其复制到这里:

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

问题

我的.feature文件是这样的:

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.

当我运行Behat测试时,这里的更多文字"被当作另一个参数,而Behat则建议另一个代码段.

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

解决方案

要解决此问题,我们必须使用不同于的另一个字符来告诉Behat存在变量,在我的情况下,我使用了单引号.

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.

因此,我已经更改了.feature,如下所示:

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"                     |

然后我更新了我的php测试实现,如下所示:

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)

调用完全相同的实现.

阅读此页面后,我想到了这个解决方案,以防有人需要.

这篇关于BDD和Behat特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆