在小黄瓜中使用适当的语法 [英] Using proper grammar in Gherkin

查看:99
本文介绍了在小黄瓜中使用适当的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查找有关Gherkin的文档似乎非常困难,因此我想知道是否存在一种方法来扩展步骤定义以使测试人员能够使用适当的语法。显示我的意思的一个示例是:

It seems to be very difficult to look up documentation about Gherkin, so I was wondering if there was a way to augment step definitions to enable the tester to use proper grammar. One example that shows what I mean is:

...Testing...
Then I see there is 1 item
...More testing...
Then I see there are 2 items

很显然,这两个步骤将使用相同的代码。我定义了一个这样的步骤定义,它几乎可以起作用:

Obviously, these two steps would use the same code. I defined a step definition like this which almost works:

Then(/^I see there (is|are) (\d+) item(s)?$/) do |item_count|
  ...code...
end

除非问题是它将 is / are 和可选的复数 s 解释为参数。是否有任何方式向Gherkin发出信号,只是为了允许适当的语法?

Except the problem is that it interprets is/are and the optional plural s as arguments. Is there any way to signal to Gherkin that these are just for allowing proper grammar?

推荐答案

使用?:

/^I see there (?:is|are) (\d+) item(?:s)?$/

这篇关于在小黄瓜中使用适当的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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