【发布时间】:2015-05-08 06:50:51
【问题描述】:
我目前正在尝试测试一项服务,该服务应该能够正确替换特定 Unicode 范围内的特定特殊字符,包括表情符号、交通图标、表情符号和装饰符号。我一直在使用 Cucumber 和 Ruby 进行测试,我最新的场景大纲不起作用。我已经尝试查找从示例表中获取字符的其他方法,但是我似乎无法使其正常工作,并且黄瓜打印输出只是抱怨未定义给定步骤。
这是我的功能场景:
Scenario Outline: I update a coupon with a name including emojis/emoticons/dingbats/symbols
Given I have a name variable with a <character> included
When I patch my coupon with this variable
Then the patch should succeed
And the name should include replacement characters
Examples:
| character |
| ???? |
| ???? |
| ???? |
| ???? |
| ☀ |
| ☂ |
| ✋ |
| ✂ |
| ⨕ |
| ???? |
| ???? |
这是我对 Given 的步骤定义(这是抱怨未定义的步骤)
Given(/^I have a name variable with a (\w+) included$/) do |char|
@name = 'min length ' + char
@json = { 'name' => @name }.to_json
end
我尝试使用一些正则表达式来捕获字符,以及 (\w+) 和 (\d+),但我找不到有关如何捕获特殊字符的信息。我可以编写 11 个不同的步骤定义,但这样的做法太糟糕了,我会发疯的。
【问题讨论】:
-
除非您的特价商品中有空格,否则使用 dot
(/^I have a name variable with a (.+?) included$/或 non-space\S:(/^I have a name variable with a (\S+) included$/是安全的。\w不会给你想要的结果,因为\w被解析为[a-zA-Z0-9_]。 -
(\S+) 工作得很好,但是 (.+?) 由于某种原因没有。请把它写成答案,这样我就可以给你信用了! :)